local extension = Package:new("ysch3")
extension.extensionName = "ysch_Al"

local U = require "packages/utility/utility"

--获得一名角色的明置手牌id列表
---@param player ServerPlayer | Player @ 目标角色
---@return integer[]
local GetShownCards = function (player)
    return table.filter(player:getCardIds("h"), function (id)
      return Fk:getCardById(id):getMark(MarkEnum.ShownCards) > 0 or
        table.find(MarkEnum.TempMarkSuffix, function (suffix)
          return Fk:getCardById(id):getMark(MarkEnum.ShownCards..suffix) > 0
        end)
    end)
end
-- 将一张牌给某角色蓄谋
--先把半成品蓄谋放在这里，铝宝智慧不靠其他扩展……
---@param player ServerPlayer @ 操作蓄谋的玩家
---@param card integer | Card  @ 用来蓄谋的牌
---@param skill_name? string @ 技能名
---@param proposer? integer @ 移动操作者的id
---@return nil
local premeditate = function(player, card, skill_name, proposer)
    skill_name = skill_name or ""
    proposer = proposer or player.id
    local room = player.room
    if type(card) == "table" then
      assert(not card:isVirtual() or #card.subcards == 1)
      card = card:getEffectiveId()
    end
    local xumou = Fk:cloneCard("ysch_Al__premeditate")
    if Fk.skills["#premeditate_rule"] then
        xumou = Fk:cloneCard("premeditate")
    elseif Fk.skills["#tuntian_premeditate_rule"] then
        xumou = Fk:cloneCard("tuntian__premeditate")
    end
    xumou:addSubcard(card)
    room:sendLog{
      type = "#premeditate",
      from = proposer,
      to = {player.id},
    }
    player:addVirtualEquip(xumou)
    room:moveCardTo(xumou, Player.Judge, player, fk.ReasonJustMove, skill_name, nil, false, proposer, "", {proposer, player.id})
end
if not Fk.skills["#rfenghou__premeditate_rule"] and not Fk.skills["#premeditate_rule"] and not Fk.skills["#tuntian_premeditate_rule"] then
    local premeditate_rule = fk.CreateTriggerSkill{
        name = "#rfenghou__premeditate_rule",
        events = {fk.EventPhaseStart},
        mute = true,
        global = true,
        priority = 0,
        can_trigger = function(self, event, target, player, data)
            return target == player and player.phase == Player.Judge
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local cards = player:getCardIds(Player.Judge)
            for i = #cards, 1, -1 do
                if table.contains(player:getCardIds(Player.Judge), cards[i]) then
                if player.dead then return end
                local xumou = player:getVirualEquip(cards[i])
                if xumou and xumou.trueName == "premeditate" then
                    local use = U.askForUseRealCard(room, player, {cards[i]}, ".", "premeditate",
                    "#premeditate-use:::"..Fk:getCardById(cards[i], true):toLogString(),
                    {expand_pile = {cards[i]}, extra_use = true}, true, true)
                    if use then
                    room:setPlayerMark(player, "premeditate_"..use.card.trueName.."-phase", 1)
                    use.extra_data = use.extra_data or {}
                    use.extra_data.premeditate = true
                    room:useCard(use)
                    else
                    break
                    end
                end
                end
            end
            cards = player:getCardIds(Player.Judge)
            local xumou = table.filter(cards, function(id)
                local card = player:getVirualEquip(id)
                return card and card.name == "rfenghou__premeditate"
            end)
            room:moveCardTo(xumou, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "premeditate", nil, true, player.id)
        end,
    }
    local premeditate_prohibit = fk.CreateProhibitSkill{
        name = "#rfenghou__premeditate_prohibit",
        global = true,
        prohibit_use = function(self, player, card)
            return card and player:getMark("premeditate_"..card.trueName.."-phase") > 0
        end,
    }
    local premeditate_visible = fk.CreateVisibilitySkill{
        name = "#rfenghou__premeditate_visible",
        global = true,
        card_visible = function(self, player, card)
            local owner = Fk:currentRoom():getCardOwner(card.id)
            if owner then
                local vcard = owner:getVirualEquip(card.id)
                if vcard and vcard.name == "rfenghou__premeditate" then
                return false
                end
            end
        end
    }
    Fk:addSkill(premeditate_rule)
    Fk:addSkill(premeditate_prohibit)
    Fk:addSkill(premeditate_visible)
    Fk:loadTranslationTable{
        ["#premeditate"] = "%from 对 %to 进行了蓄谋",
        ["#premeditate-use"] = "你可以使用此蓄谋牌%arg，或点“取消”将所有蓄谋牌置入弃牌堆",
    }
end
local getShade = function (room, n)
    n = n or 1
    local ids = {}
    local name
    if Fk.all_card_types["shade"] then
        name = "shade"
    elseif Fk.all_card_types["rfenghou__shade"] then
        name = "rfenghou__shade"
    end
    assert(name, "服务器未加入【影】！请联系管理员安装“江山如故”或“封侯”包")
    for _, id in ipairs(room.void) do
      if n <= 0 then break end
      if Fk:getCardById(id).name == name then
        room:setCardMark(Fk:getCardById(id), MarkEnum.DestructIntoDiscard, 1)
        table.insert(ids, id)
        n = n - 1
      end
    end
    while n > 0 do
      local card = room:printCard(name, Card.Spade, 1)
      room:setCardMark(card, MarkEnum.DestructIntoDiscard, 1)
      table.insert(ids, card.id)
      n = n - 1
    end
    return ids
end
local getAllCardNames = function(card_type, true_name)
    local all_names = {}
    local basics = {}
    local normalTricks = {}
    local delayedTricks = {}
    local equips = {}
    for _, card in ipairs(Fk.cards) do
        if card.package and not table.contains(Fk:currentRoom().disabled_packs, card.package.name) and not card.is_derived then
            if card.type == Card.TypeBasic then
                table.insertIfNeed(basics, true_name and card.trueName or card.name)
            elseif card.type == Card.TypeTrick and card.sub_type ~= Card.SubtypeDelayedTrick then
                table.insertIfNeed(normalTricks, true_name and card.trueName or card.name)
            elseif card.type == Card.TypeTrick and card.sub_type == Card.SubtypeDelayedTrick then
                table.insertIfNeed(delayedTricks, true_name and card.trueName or card.name)
            elseif card.type == Card.TypeEquip then
                table.insertIfNeed(equips, true_name and card.trueName or card.name)
            end
        end
    end
    if card_type:find("b") then
        table.insertTable(all_names, basics)
    end
    if card_type:find("t") then
        table.insertTable(all_names, normalTricks)
    end
    if card_type:find("d") then
        table.insertTable(all_names, delayedTricks)
    end
    if card_type:find("e") then
        table.insertTable(all_names, equips)
    end
    return all_names
end

---@param player ServerPlayer @ 目标角色
local DIYEnterHidden = function (player)
    local room = player.room
    room:sendLog({
      type = "#EnterHidden",
      from = player.id,
    })
    local skills = "hidden_skill&"
    room:setPlayerMark(player, "__hidden_general", player.general)
    for _, s in ipairs(Fk.generals[player.general]:getSkillNameList(true)) do
      if player:hasSkill(s, true) then
        skills = skills.."|-"..s
      end
    end
    if player.deputyGeneral ~= "" then
      room:setPlayerMark(player, "__hidden_deputy", player.deputyGeneral)
      for _, s in ipairs(Fk.generals[player.deputyGeneral]:getSkillNameList(true)) do
        if player:hasSkill(s, true) then
          skills = skills.."|-"..s
        end
      end
    end
    player.general = "hiddenone"
    player.gender = General.Male
    room:broadcastProperty(player, "gender")
    if player.deputyGeneral ~= "" then
      player.deputyGeneral = ""
    end
    player.kingdom = "jin"
    room:setPlayerMark(player, "__hidden_record",
    {
      maxHp = player.maxHp,
      hp = player.hp,
    })
    player.maxHp = 1
    player.hp = 1
    for _, property in ipairs({"general", "deputyGeneral", "kingdom", "maxHp", "hp"}) do
      room:broadcastProperty(player, property)
    end
    room:handleAddLoseSkills(player, skills, nil, false, true)
end

--添加英文到中文的翻译
Fk:loadTranslationTable{
    ["#EnterHidden"] = "%from 进入隐匿状态",
    ["ysch3"] = "疑似持恒",--小包名
}

local lukang = General:new(extension, "ysch3__lukang", "wu", 4, 4, General.Male)--
local lukang1 = General:new(extension, "ysch3__lukang1", "wu", 4, 4, General.Male)--
local lukang2 = General:new(extension, "ysch3__lukang2", "wu", 4, 4, General.Male)--
local lukang3 = General:new(extension, "ysch3__lukang3", "wu", 4, 4, General.Male)--
local lukang4 = General:new(extension, "ysch3__lukang4", "wu", 4, 4, General.Male)--
lukang1.total_hidden = true
lukang2.total_hidden = true
lukang3.total_hidden = true
lukang4.total_hidden = true
Fk:loadTranslationTable{
    ["ysch3__lukang"] = "陆抗",
    ["ysch3__lukang1"] = "陆抗",
    ["ysch3__lukang2"] = "陆抗",
    ["ysch3__lukang3"] = "陆抗",
    ["ysch3__lukang4"] = "陆抗",
    ["#ysch3__lukang"] = "社稷之瑰宝",
    ["designer:ysch3__lukang"] = "铝",
    ["cv:ysch3__lukang"] = "官方",
    ["illustrator:ysch3__lukang"] = "威风",
}
local function ysch3_poshi(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player,"ysch3_poshi","big")
    player:broadcastSkillInvoke("ysch3_poshi")
    if type(room:getBanner("@&ysch3_jiangdonghuchen")) == "table" then
        local general = room:askForGeneral(player, room:getBanner("@&ysch3_jiangdonghuchen"), 1)
        player:setSkillUseHistory("ysch3_poshi",1,Player.HistoryGame)
        room:changeHero(player, general, true, false, true, true, true)
        room:handleAddLoseSkills(player,"-ysch3_jieze",nil,true)
        room:handleAddLoseSkills(player,"-ysch3_poshi",nil,true)
    end
end
local jieze = fk.CreateViewAsSkill{
    name = "ysch3_jieze",
    pattern = ".",
    prompt = "#ysch3_jieze",
    interaction = function()
        local names, all_names = {}, {}
        for _, id in ipairs(Fk:getAllCardIds()) do
            local card = Fk:getCardById(id)
            if (card.type == Card.TypeBasic or card:isCommonTrick()) and not card.is_derived  and not card.multiple_targets then
                table.insertIfNeed(all_names, card.name)
                local to_use = Fk:cloneCard(card.name)
                if ((Fk.currentResponsePattern == nil and Self:canUse(to_use) and not Self:prohibitUse(to_use)) or
                    (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use))) then
                    table.insertIfNeed(names, card.name)
                end
            end
        end
        if #names == 0 then return false end
        return U.CardNameBox { choices = names, all_choices = all_names }
    end,
    view_as = function(self, cards)
        if not self.interaction.data then return end
        local card = Fk:cloneCard(self.interaction.data)
        card.skillName = self.name
        return card
    end,
    before_use = function(self, player, use)
        local room = player.room
        room:addPlayerMark(player, "ysch3_jieze_number", 1)
        if Fk:translate(player.general,"zh_CN") == "陆抗" then
            player.general = "ysch3__lukang"..tostring(player:getMark("ysch3_jieze_number"))
            room:broadcastProperty(player, "general")
        end
        if player:getMark("ysch3_jieze_number") >= 4 and player:hasSkill("ysch3_poshi") then
            local result = room:askForSkillInvoke(player,"ysch3_poshi")
            if result then
                ysch3_poshi(self,nil,player,player)
                room:handleAddLoseSkills(player,"-ysch3_jieze",nil,true)
                room:handleAddLoseSkills(player,"-ysch3_poshi",nil,true)
            end
        end
    end,
    times = function(self)
        return 4 - Self:getMark("ysch3_jieze_number")
    end,
    enabled_at_play = function(self, player)
        return player:getMark("ysch3_jieze_number") < 4 and player:usedSkillTimes(self.name, Player.HistoryTurn) < 1
    end,
    enabled_at_response = function(self, player, response)
        return player:getMark("ysch3_jieze_number") < 4 and player:usedSkillTimes(self.name, Player.HistoryTurn) < 1
    end,
}
lukang:addSkill(jieze)
local poshi = fk.CreateTriggerSkill{
    name = "ysch3_poshi",
    frequency = Skill.Limited,
    on_lose = function (self, player, is_death)
        local room = player.room
        if player:usedSkillTimes(self.name, Player.HistoryGame) < 1 then
            local result = room:askForSkillInvoke(player,"ysch3_poshi")
            if result then
                ysch3_poshi(self,nil,player,player)
                room:handleAddLoseSkills(player,"-ysch3_jieze",nil,true)
                room:handleAddLoseSkills(player,"-ysch3_poshi",nil,true)
            end
        end
    end,
    refresh_events = {fk.GameStart},
    can_refresh = function (self, event, target, player, data)
        return player:hasSkill(self)
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local hucheng = {"程普","黄盖","韩当","蒋钦","周泰","陈武","董袭","甘宁","凌统","徐盛","潘璋","丁奉"}
        local generals = {}
        local function shuffleArray(array)
            local shuffled = {}
            local new_shuffled = {}
            for i, v in ipairs(array) do
                shuffled[i] = v
            end
            local n = #shuffled
            for i = 1,n do
                local randomOne = table.random(shuffled, 1)[1]
                table.insert(new_shuffled,randomOne)
                table.removeOne(shuffled,randomOne)
            end
            return new_shuffled
        end
        local general_pile = table.random(shuffleArray(room.general_pile),#room.general_pile)
        for _, general in ipairs(hucheng) do
            for _, g in ipairs(general_pile) do
                if string.find(Fk:translate(g),general) ~= nil then
                    if not table.contains(generals,g) then
                        table.insert(generals,g)
                    end
                    break
                end
            end
        end
        while #generals < 12 do
            for _, g in ipairs(general_pile) do
                if string.find(Fk:translate(g),hucheng[1]) == nil and string.find(Fk:translate(g),hucheng[2]) == nil  and string.find(Fk:translate(g),hucheng[3]) == nil and
                string.find(Fk:translate(g),hucheng[4]) == nil and string.find(Fk:translate(g),hucheng[5]) == nil  and string.find(Fk:translate(g),hucheng[6]) == nil and
                string.find(Fk:translate(g),hucheng[7]) == nil and string.find(Fk:translate(g),hucheng[8]) == nil  and string.find(Fk:translate(g),hucheng[9]) == nil and
                string.find(Fk:translate(g),hucheng[10]) == nil and string.find(Fk:translate(g),hucheng[11]) == nil  and string.find(Fk:translate(g),hucheng[12]) == nil and
                Fk.generals[g].kingdom == "wu" and Fk.generals[g].gender == General.Male then
                    table.insert(generals,g)
                    if #generals > 11 then
                        break
                    end
                end
            end
        end
        if room:getBanner("@&ysch3_jiangdonghuchen") == nil then
            room:setBanner("@&ysch3_jiangdonghuchen", generals)
        end
    end,
}
lukang:addSkill(poshi)
Fk:loadTranslationTable{
    ["ysch3_jieze"] = "竭泽",
    [":ysch3_jieze"] = "回合技，你可以撕去武将牌的1/4以视为使用一张单目标即时牌。",
    ["#ysch3_jieze"] = "竭泽：你可以撕去1/4的武将牌以视为使用一张单目标即时牌。",
    ["ysch3_poshi"] = "破势",
    [":ysch3_poshi"] = "限定技，当你失去该武将牌时，你可以从“<a href='ysch3_jiangdonghuchen'>江东虎臣</a>”池子中选择一张顶替之。",
    ["ysch3_jiangdonghuchen"] = "游戏开始时，从剩余武将牌堆中抽取不重名的程普、黄盖、韩当、蒋钦、周泰、陈武、董袭、甘宁、凌统、徐盛、潘璋、丁奉组成“江东虎臣”将池。（不足12张则从剩余吴势力男武将补足）",
    ["@&ysch3_jiangdonghuchen"] = "江东虎臣将池",

    ["$ysch3_jieze1"] = "毁堰废坝，阻晋军粮道",
    ["$ysch3_jieze2"] = "吾已毁堰阻碍，晋军已计，也难施",
    ["$ysch3_poshi1"] = "破晋军雄威，断敌心谋略",
    ["$ysch3_poshi2"] = "良谋益策，破敌腹背",
}

local xiahouyuan = General:new(extension, "ysch3__xiahouyuan", "wei", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__xiahouyuan"] = "夏侯渊",
    ["#ysch3__xiahouyuan"] = "灵魂疾行",
    ["designer:ysch3__xiahouyuan"] = "铝&玊璞瑜瑾",
    ["cv:ysch3__xiahouyuan"] = "官方",
    ["illustrator:ysch3__xiahouyuan"] = "瞌瞌一休",
}
local shensu = fk.CreateTriggerSkill{
    name = "ysch3_shensu",
    events = {fk.EventPhaseStart},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self) and target == player and target.phase == Player.Judge
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askForSkillInvoke(player, self.name, nil, "#ysch3_shensu-invoke::"..player:getNextAlive().id)
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local bool = true
        while bool do
            local judge
            judge = {
                who = player,
                reason = "lightning",
                pattern = ".|2~9|spade",
            }
            room:judge(judge)
            if judge.card:matchPattern(".|2~9|spade") then
                bool = false
                room:damage{
                    to = judge.who,
                    damage = 3,
                    damageType = fk.ThunderDamage,
                    skillName = self.name,
                }
            else
                room:swapSeat(player, room:getPlayerById(player:getNextAlive().id))
                bool = player.room:askForSkillInvoke(player, self.name, nil, "#ysch3_shensu-invoke::"..player:getNextAlive().id)
                if bool then
                    room:notifySkillInvoked(player,self.name,"special")
                    player:broadcastSkillInvoke(self.name)
                end
            end
        end
    end,
}
xiahouyuan:addSkill(shensu)
Fk:loadTranslationTable{
    ["ysch3_shensu"] = "神速",
    [":ysch3_shensu"] = "你可以如【闪电】般移动，亦须如【闪电】般判定。",
    ["#ysch3_shensu-invoke"] = "是否发动 神速，进行【闪电】判定，然后与%dest交换座位",

    ["$ysch3_shensu1"] = "吾等无需恋战",
    ["$ysch3_shensu2"] = "吾自当以一当十速战速决",
}

local masu = General:new(extension, "ysch3__masu", "shu", 3, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__masu"] = "马谡",
    ["#ysch3__masu"] = "过嘉簿识",
    ["designer:ysch3__masu"] = "铝&朱苦力",
    ["cv:ysch3__masu"] = "官方",
    ["illustrator:ysch3__masu"] = "匠人绘",
}
local xutan = fk.CreateActiveSkill{
    name = "ysch3_xutan",
    anim_type = "offensive",
    prompt = "#ysch3_xutan",
    min_target_num = 1,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected, selected_cards, _, _, player)
        return to_select~=player.id
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local to = room:getPlayerById(effect.tos[1])
        room:damage{
            from = player,
            to = to,
            damage = 1,
            skillName = self.name,
        }
    end,
    can_use = function (self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
}
local xutan_use = fk.CreateTriggerSkill{
    name = "#ysch3_xutan_use",
    mute = true,
    events = {fk.DamageCaused},
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill("ysch3_xutan") and player == target and data.skillName == "ysch3_xutan"
    end,
    on_cost = function (self, event, target, player, data)
        return player.room:askForSkillInvoke(player, self.name, nil, "#ysch3_xutan-use::"..data.to.id)
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        data.isVirtualDMG = true
        room:useVirtualCard("ysch_Al__foresight", nil, player, {player}, self.name)
    end,
}
xutan:addRelatedSkill(xutan_use)
masu:addSkill(xutan)
Fk:addPoxiMethod{
    name = "ysch3_xinzhan_poxi",
    card_filter = function(to_select, selected, data)
        for _, areas in ipairs(data) do
            if #table.filter(selected,function (id)
                return table.contains(areas[2],id)
            end)>0 and table.contains(areas[2],to_select) then
               return false 
            end
        end
        return #selected < 1
    end,
    feasible = function(selected, data)
      return data and #selected == 1
    end,
    prompt = function (data, extra_data)
        if extra_data == "ysch3_xinzhan_snatch_skill" then
            return "#snatch_skill"
        else
            return "#dismantlement_skill"
        end
    end,
    default_choice = function (data)
        if not data then return {} end
        local cids = table.map(data,function (v)
            return v[2][1]
        end)
        return cids
    end,
}
local xinzhan_snatchSkill = fk.CreateActiveSkill{
    name = "ysch3_xinzhan_snatch_skill",
    prompt = "#snatch_skill",
    can_use = Util.CanUse,
    distance_limit = 1,
    mod_target_filter = function(self, to_select, selected, player, card, distance_limited)
        local target = Fk:currentRoom():getPlayerById(to_select)
        return target ~= player and not (target:isAllNude() or (distance_limited and not self:withinDistanceLimit(player, false, card, target)))
    end,
    target_filter = Util.TargetFilter,
    target_num = 1,
    on_effect = function(self, room, effect)
        local from = room:getPlayerById(effect.from)
        local to = room:getPlayerById(effect.to)
        if from.dead or to.dead or to:isAllNude() then return end
        local bool = false
        local card_data = {}
        local ids = {}
        if to:getHandcardNum() > 0 then
            local handcards = {}
            for _, id in ipairs(to:getCardIds(Player.Hand)) do
                if Fk:getCardById(id).suit == Card.Heart then
                    table.insert(ids, id)
                    table.insert(handcards, -1) -- 手牌不可见
                end
            end
            if #handcards > 0 then
                bool = true
                table.insert(card_data, {"$Hand", handcards})
            end
        end
        local areas = { {"$Equip", Player.Equip}, {"$Judge", Player.Judge} }
        for _, v in ipairs(areas) do
            local area = v[2]
            local areaC = table.filter(to:getCardIds(area), function (id)
                return Fk:getCardById(id).suit == Card.Heart
            end)
            if #areaC > 0 then
                bool = true
                table.insert(card_data, {v[1], areaC})
            end
        end
        if bool == false then return end

        local ret = room:askForPoxi(from, "ysch3_xinzhan_poxi", card_data, self.name, false)
        local new_ret = table.filter(ret, function(id) return id ~= -1 end)
        local hand_num = #ret - #new_ret
        if hand_num > 0 then
            table.insertTable(new_ret, table.random(ids, hand_num))
        end

        local cid = new_ret[1]
        room:obtainCard(from, cid, false, fk.ReasonPrey)
    end
}
xinzhan_snatchSkill.cardSkill = true
Fk:addSkill(xinzhan_snatchSkill)
local xinzhan_dismantlementSkill = fk.CreateActiveSkill{
    name = "ysch3_xinzhan_dismantlement_skill",
    prompt = "#dismantlement_skill",
    can_use = Util.CanUse,
    target_num = 1,
    mod_target_filter = function(self, to_select, selected, player, card)
        return to_select ~= player.id and not Fk:currentRoom():getPlayerById(to_select):isAllNude()
    end,
    target_filter = Util.TargetFilter,
    on_effect = function(self, room, effect)
        local from = room:getPlayerById(effect.from)
        local to = room:getPlayerById(effect.to)
        if from.dead or to.dead or to:isAllNude() then return end
        local bool = false
        local card_data = {}
        local ids = {}
        if to:getHandcardNum() > 0 then
            local handcards = {}
            for _, id in ipairs(to:getCardIds(Player.Hand)) do
                if Fk:getCardById(id).suit == Card.Heart then
                    table.insert(ids, id)
                    table.insert(handcards, -1) -- 手牌不可见
                end
            end
            if #handcards > 0 then
                bool = true
                table.insert(card_data, {"$Hand", handcards})
            end
        end
        local areas = { {"$Equip", Player.Equip}, {"$Judge", Player.Judge} }
        for _, v in ipairs(areas) do
            local area = v[2]
            local areaC = table.filter(to:getCardIds(area), function (id)
                return Fk:getCardById(id).suit == Card.Heart
            end)
            if #areaC > 0 then
                bool = true
                table.insert(card_data, {v[1], areaC})
            end
        end
        if bool == false then return end

        local ret = room:askForPoxi(from, "ysch3_xinzhan_poxi", card_data, self.name, false)
        local new_ret = table.filter(ret, function(id) return id ~= -1 end)
        local hand_num = #ret - #new_ret
        if hand_num > 0 then
            table.insertTable(new_ret, table.random(ids, hand_num))
        end

        local cid = new_ret[1]
        room:throwCard({cid}, self.name, to, from)
    end
}
xinzhan_dismantlementSkill.cardSkill = true
Fk:addSkill(xinzhan_dismantlementSkill)
local xinzhan_foresightSkill = fk.CreateActiveSkill{
    name = "ysch3_xinzhan_foresight_skill",
    mod_target_filter = Util.TrueFunc,
    can_use = function(self, player, card)
        return Util.SelfCanUse(self, player, card)
    end,
    on_use = function(self, room, cardUseEvent)
        if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
        cardUseEvent.tos = {{cardUseEvent.from}}
        end
    end,
    on_effect = function(self, room, effect)
        local to = room:getPlayerById(effect.to)
        local cards = {}
        for i = 1, 2, 1 do
            for j, id in ipairs(room.draw_pile) do
                local c = Fk:getCardById(id)
                if c.suit == Card.Heart then
                    table.insert(cards,id)
                    if #cards > 1 then
                        break
                    end
                end
            end
            if #cards > 1 then
                break
            else
                room:shuffleDrawPile()
            end
        end
        if #cards > 0 then
            for _, v in ipairs(cards) do
                table.removeOne(room.draw_pile, v)
            end
            room:askForGuanxing(to, cards, nil, nil)
        end
        room:drawCards(to, 2, self.name)
    end
}
xinzhan_foresightSkill.cardSkill = true
Fk:addSkill(xinzhan_foresightSkill)
local xinzhan = fk.CreateTriggerSkill{
    name = "ysch3_xinzhan",
    frequency = Skill.Compulsory,
    events = {fk.PreCardEffect},
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self.name) and data.from == player.id and table.contains({"snatch","dismantlement","foresight"},data.card.trueName)
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local card = data.card:clone()
        local c = table.simpleClone(data.card)
        for k, v in pairs(c) do
        card[k] = v
        end
        if data.card.trueName == "snatch" then
            card.skill = xinzhan_snatchSkill
        else if data.card.trueName == "dismantlement" then
            card.skill = xinzhan_dismantlementSkill
            else if data.card.trueName == "foresight" then
                card.skill = xinzhan_foresightSkill
                end
            end
        end
        data.card = card
    end,
}
masu:addSkill(xinzhan)
Fk:loadTranslationTable{
    ["ysch3_xutan"] = "虚谈",
    [":ysch3_xutan"] = "出牌阶段限一次，你可对一名其他角色造成1点伤害。你可令此伤害视为视为以视为使用一张【洞烛先机】。",
    ["#ysch3_xutan_use"] = "虚谈",
    ["#ysch3_xutan"] = "虚谈：对一名其他角色造成1点伤害",
    ["#ysch3_xutan-use"] = "虚谈：是否令你对%dest造成的伤害改为视为伤害，然后视为使用【洞烛先机】",
    ["ysch3_xinzhan"] = "心战",
    [":ysch3_xinzhan"] = "锁定技，你对其他角色使用【顺手牵羊】/【过河拆桥】或通过【洞烛先机】卜算牌堆时，忽略其中非<font color='red'>♥</font>牌。",
    ["ysch3_xinzhan_poxi"] = "心战",
    ["$Hand"] = "手牌区",
    ["$Equip"] = "装备区",
    ["$Judge"] = "判定区",
    ["$Hand_opposite"] = "对方手牌区",
    ["$Equip_opposite"] = "对方装备区",
    ["$Judge_opposite"] = "对方判定区",

    ["$ysch3_xutan1"] = "吾有一计，可致司马懿于死地。",
    ["$ysch3_xutan2"] = "丞相勿忧，司马懿不足为患。",
    ["$ysch3_xinzhan1"] = "覆军杀将非良策也，当服其心以求长远。",
    ["$ysch3_xinzhan2"] = "欲平南中之叛，当以攻心为上。",
}

local sunhao = General:new(extension, "ysch3__sunhao", "wu", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__sunhao"] = "孙皓",
    ["#ysch3__sunhao"] = "暴戾恣雎",
    ["designer:ysch3__sunhao"] = "铝",
    ["cv:ysch3__sunhao"] = "官方",
    ["illustrator:ysch3__sunhao"] = "匠人绘",
}
local yinwei = fk.CreateActiveSkill{
    name = "ysch3_yinwei",
    anim_type = "support",
    prompt = "#ysch3_yinwei",
    min_target_num = 1,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected, selected_cards, _, _, player)
        return to_select~=player.id
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local to = room:getPlayerById(effect.tos[1])
        local card = room:askForDiscard(to, 1, 1, true, self.name, true, ".|.|.|.|.|equip", "#ysch3_yinwei-invoke1::"..player.id)
        if #card == 0 then
            local c = Fk:cloneCard("ysch_Al__sincere_treat")
            c.skillName = self.name
            local use = {
                from = player.id,
                tos = table.map(effect.tos, function (id) return {id} end),
                card = c,
            }
            room:useCard(use)
            local card2 = room:askForDiscard(to, 1, 1, true, self.name, true, ".|.|.|.|.|equip", "#ysch3_yinwei-invoke2::"..player.id)
            if #card2 == 0 then
                room:damage{
                    from = player,
                    to = to,
                    damage = 1,
                    skillName = self.name,
                }
                room:changeMaxHp(to, 1)
            end
        end
    end,
    can_use = function (self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
}
sunhao:addSkill(yinwei)
Fk:loadTranslationTable{
    ["ysch3_yinwei"] = "淫威",
    [":ysch3_yinwei"] = "出牌阶段限一次，你可以令一名其他角色弃置一张装备牌，若做不到，你视为对其使用一张【推心置腹】，若还做不到，对其造成1点伤害再令其加1点体力上限。",
    ["#ysch3_yinwei"] = "淫威：令一名其他角色弃置一张装备牌，若做不到，对其施加惩罚",
    ["#ysch3_yinwei-invoke1"] = "淫威：请弃置一张装备牌，否则%dest视为对你使用【推心置腹】",
    ["#ysch3_yinwei-invoke2"] = "淫威：请弃置一张装备牌，否则%dest对你造成1点伤害，你加1点体力上限",

    ["$ysch3_yinwei"] = "这天下的一切，都是朕的！",
}

local zhangxuan = General:new(extension, "ysch3__zhangxuan", "wu", 3, 3, General.Female)--
local zhangxuan2 = General:new(extension, "ysch3__zhangxuan2", "wu", 3, 3, General.Female)--
zhangxuan2.total_hidden = true
Fk:loadTranslationTable{
    ["ysch3__zhangxuan"] = "张嫙",
    ["ysch3__zhangxuan2"] = "张嫙",
    ["#ysch3__zhangxuan"] = "玉宇嫁蔷",
    ["designer:ysch3__zhangxuan"] = "铝",
    ["cv:ysch3__zhangxuan"] = "官方",
    ["illustrator:ysch3__zhangxuan"] = "匠人绘",
}
local tongli = fk.CreateActiveSkill{
    name = "ysch3_tongli",
    switch_skill_name = "ysch3_tongli",
    card_filter = Util.FalseFunc,
    target_num = 0,
    target_filter = function(self, to_select, selected, selected_cards, _, _, player)
        local c = Fk:cloneCard("jintuiziru")
        c.skillName = self.name
        return c.skill:targetFilter(to_select, selected, selected_cards, c, nil, player) and
        not player:isProhibited(Fk:currentRoom():getPlayerById(to_select), c)
    end,
    can_use = function (self, player, card, extra_data)
        if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
            return player:hasSkill(self.name) and player:getMark("ysch3_tongli_ying-phase") == 0
        else
            return player:hasSkill(self.name) and player:getMark("ysch3_tongli_yang-phase") == 0
        end
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local c = Fk:cloneCard("jintuiziru")
        local targets = table.filter(room:getOtherPlayers(player),function (p)
            return p:isMale()
        end)
        if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
            if #targets > 0 then
                table.insert(targets,player)
            end
            room:setPlayerMark(player,"ysch3_tongli_yang-phase",1)
            player.general = "ysch3__zhangxuan2"
            room:changeMaxHp(player, 1)
            room:broadcastProperty(player, "general")
        else
            c = Fk:cloneCard("ysch_Al__drowning")
            room:setPlayerMark(player,"ysch3_tongli_ying-phase",1)
            player.general = "ysch3__zhangxuan"
            room:changeMaxHp(player, -1)
            room:broadcastProperty(player, "general")
        end
        if #targets == 0 then
            c = Fk:cloneCard("ysch_Al__wd_stop_thirst")
            targets = table.filter(room.players,function (p)
                return not p:isMale()
            end)
        end
        c.skillName = self.name
        local use = {
            from = player.id,
            tos = table.map(targets, function (p) return {p.id} end),
            card = c,
        }
        room:useCard(use)
    end
}
zhangxuan:addSkill(tongli)
Fk:loadTranslationTable{
    ["ysch3_tongli"] = "同礼",
    [":ysch3_tongli"] = "转换技，每回合每项限一次，你可以①加②减1点体力上限，视为对男性角色使用一张①【进退自如】②【水淹七军】。若无男性角色，改为同女性角色使用一张【望梅止渴】。",

    ["$ysch3_tongli1"] = "胞妹殊礼，妾幸同之。",
    ["$ysch3_tongli2"] = "夫妻之礼，举案齐眉。",
}
local sunshangxiang = General:new(extension, "ysch3__sunshangxiang", "wu", 3, 3, General.Female)--
Fk:loadTranslationTable{
    ["ysch3__sunshangxiang"] = "孙尚香",
    ["#ysch3__sunshangxiang"] = "鸳袖衔剑珮",
    ["designer:ysch3__sunshangxiang"] = "铝",
    ["cv:ysch3__sunshangxiang"] = "官方",
    ["illustrator:ysch3__sunshangxiang"] = "Jzeo",
}
local jieyin = fk.CreateActiveSkill{
    name = "ysch3_jieyin",
    mute = true,
    anim_type = "support",
    prompt = function (self)
        if Self:getMark("ysch3_jieyin") ~= 0 then
            return "#ysch3_jieyin-gain::"..Self:getMark("ysch3_jieyin")
        end
        return "#ysch3_jieyin"
    end,
    min_target_num = 1,
    card_num = 1,
    card_filter = function(self, to_select, selected)
        return #selected < 1 and not Self:prohibitDiscard(Fk:getCardById(to_select))
    end,
    target_filter = function(self, to_select, selected, selected_cards, _, _, player)
        local target = Fk:currentRoom():getPlayerById(to_select)
        return to_select ~= player.id and (target:isWounded() or player:isWounded())
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local to = room:getPlayerById(effect.tos[1])
        local bool = true
        room:throwCard(effect.cards, self.name, player, player)
        player:broadcastSkillInvoke(self.name)
        if player:getMark("ysch3_jieyin") ~= 0 and player:getMark("ysch3_jieyin") ~= effect.tos[1] then
            local tp = room:getPlayerById(player:getMark("ysch3_jieyin"))
            if not tp:isKongcheng() and not to.dead then
                bool = false
                room:notifySkillInvoked(player,self.name,"control")
                room:moveCardTo(tp:getCardIds("h"), Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
                if not to.dead and not player.dead then
                    local cards = player:getCardIds("he")
                    local n = tp.hp
                    if n < #cards then
                        cards = room:askForCard(player, n, n, true, self.name, false, ".", "#ysch3_jieyin-give::"..tp.id..":"..n)
                    end
                    room:moveCardTo(cards, Card.PlayerHand, tp, fk.ReasonGive, self.name, nil, false, player.id)
                end
            end
        end
        if player.dead then return end
        if bool then
            room:notifySkillInvoked(player,self.name,"support")
        end
        room:setPlayerMark(player, "ysch3_jieyin", effect.tos[1])
        room:setPlayerMark(player, "@ysch3_jieyin", Fk:translate(to.general))
        if player:isWounded() and not player.dead then
            room:recover({
                who = player,
                num = 1,
                recoverBy = player,
                skillName = self.name,
            })
        end
        if to:isWounded() and not to.dead then
            room:recover({
                who = to,
                num = 1,
                recoverBy = player,
                skillName = self.name,
            })
        end
    end,
    can_use = function (self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
}
sunshangxiang:addSkill(jieyin)
local xiaoji = fk.CreateTriggerSkill{
    name = "ysch3_xiaoji",
    mute = true,
    events = {fk.TargetSpecified,fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(self) then
            if event == fk.TargetSpecified then
                if #player:getAvailableEquipSlots(Card.SubtypeWeapon) > 0 and not table.find(player:getCardIds('e'),function(cid) 
                    return Fk:getCardById(cid).name == "double_swords" end
                ) and data.card and data.card.trueName == "slash" then
                    local target = player.room:getPlayerById(data.to)
                    return player:compareGenderWith(target, true)
                end
            else
                return player.phase == Player.Finish and not player:prohibitUse(Fk:cloneCard("slash"))
            end
        end
    end,
    on_cost = function(self, event, target, player, data)
        if event == fk.EventPhaseStart then
            local room = player.room
            local success, dat = room:askForUseActiveSkill(player, "ysch3_xiaoji_viewas", "#ysch3_xiaoji-choose", true)
            if success then
                self.cost_data = dat
                return true
            end
        else
            if player.room:askForSkillInvoke(player, "double_swords") then
                return true
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        player:broadcastSkillInvoke(self.name)
        if event == fk.EventPhaseStart then
            room:notifySkillInvoked(player,self.name,"offensive")
            local card = Fk.skills["ysch3_xiaoji_viewas"]:viewAs(self.cost_data.cards)
            room:useCard{
                from = player.id,
                tos = table.map(self.cost_data.targets, function(id) return {id} end),
                card = card,
                extraUse = true,
            }
        else
            room:notifySkillInvoked(player,self.name,"special")
            local to = player.room:getPlayerById(data.to)
            if to:isKongcheng() then
                player:drawCards(1, self.name)
            else
                local result = room:askForDiscard(to, 1, 1, false, self.name, true, ".", "#double_swords-invoke:"..player.id)
                if #result == 0 then
                    player:drawCards(1, self.name)
                end
            end
        end
    end,
}
local xiaoji_viewas = fk.CreateViewAsSkill{
    name = "ysch3_xiaoji_viewas",
    pattern = "slash",
    card_filter = Util.FalseFunc,
    view_as = function(self, cards)
        local card = Fk:cloneCard("slash")
        card.skillName = "ysch3_xiaoji"
        return card
    end,
}
local xiaoji_targetmod = fk.CreateTargetModSkill{
    name = "#ysch3_xiaoji_targetmod",
    bypass_times = function(self, player, skill, scope, card)
        return card and table.contains(card.skillNames, "ysch3_xiaoji")
    end,
}
local xiaoji_attackrange = fk.CreateAttackRangeSkill{
    name = "#ysch3_iaoji_attackrange",
    fixed_func = function (self, from)
        if from:hasSkill(xiaoji) and #from:getAvailableEquipSlots(Card.SubtypeWeapon) > 0 and not table.find(from:getCardIds('e'),function(cid) 
            return Fk:getCardById(cid).attack_range and Fk:getCardById(cid).attack_range > 2 end
        ) then
            return 2
        end
    end,
}
Fk:addSkill(xiaoji_viewas)
xiaoji:addRelatedSkill(xiaoji_targetmod)
xiaoji:addRelatedSkill(xiaoji_attackrange)
sunshangxiang:addSkill(xiaoji)
Fk:loadTranslationTable{
    ["ysch3_jieyin"] = "结姻",
    [":ysch3_jieyin"] = "出牌阶段限一次，你可以弃置一张牌与一名其他角色各回复1点体力，若与上次目标不同，你先获得上次目标所有手牌再交给其等同其体力值张牌。",
    ["#ysch3_jieyin"] = "结姻：与一名其他角色各回复1点体力",
    ["#ysch3_jieyin-gain"] = "结姻：与一名其他角色各回复1点体力，若不为%dest，你要先离婚",
    ["#ysch3_jieyin-give"] = "结姻：你需交还 %dest %arg张牌",
    ["@ysch3_jieyin"] = "结姻",
    ["ysch3_xiaoji"] = "枭姬",
    [":ysch3_xiaoji"] = "你视为装备着【雌雄双股剑】。结束阶段，你可以视为使用一张【杀】。",
    ["#ysch3_xiaoji-choose"] = "枭姬：你可以视为使用一张【杀】",
    ["ysch3_xiaoji_viewas"] = "枭姬",

    ["$ysch3_jieyin1"] = "吾愿携弩，征战沙场，助君一战！",
    ["$ysch3_jieyin2"] = "两国结盟，你我都是一家人。",
    ["$ysch3_xiaoji1"] = "弓马何须忌红妆？",
    ["$ysch3_xiaoji2"] = "双剑夸巧，不让须眉！",
    ["~ysch3__sunshangxiang"] = "东途难归，初心难追。",
}
local zhurong = General:new(extension, "ysch3__zhurong", "qun", 4, 4, General.Female)--
Fk:loadTranslationTable{
    ["ysch3__zhurong"] = "祝融",
    ["#ysch3__zhurong"] = "合乎粥礼",
    ["designer:ysch3__zhurong"] = "铝",
    ["cv:ysch3__zhurong"] = "官方",
    ["illustrator:ysch3__zhurong"] = "罔両",
}
local zujian = fk.CreateActiveSkill{
    name = "ysch3_zujian",
    prompt = "#ysch3_zujian",
    anim_type = "offensive",
    target_num = 1,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected, selected_cards)
        local tp = Fk:currentRoom():getPlayerById(to_select)
        return #selected == 0 and to_select ~= Self.id and not tp:isNude() and (type(Self:getMark("ysch3_zujian-phase")) ~= "table" or not table.contains(Self:getMark("ysch3_zujian-phase"),to_select))
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local tp = room:getPlayerById(effect.tos[1])
        local arr = type(player:getMark("ysch3_zujian-phase")) == "table" and player:getMark("ysch3_zujian-phase") or {}
        local bool1, bool2 = false, true
        table.insert(arr,effect.tos[1])
        room:setPlayerMark(player,"ysch3_zujian-phase",arr)
        local card = room:askForCard(tp, 1, 1, true, self.name, false, nil, "#ysch3_zujian-give:"..player.id)
        if #card > 0 then
            room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, self.name, nil, false, tp.id, "@@ysch3_zujian-inarea")
        end
        if player:canPindian(tp) then
            local pindian = player:pindian({tp}, self.name)
            local winner = pindian.results[tp.id].winner
            if pindian.fromCard.subcards[1] == card[1] then
                bool1 = true
            end
            if winner and winner == tp then
                bool2 = false
            end
        end
        for _, id in ipairs(table.filter(player:getCardIds(Player.Hand), function (id)
            return Fk:getCardById(id):getMark("@@ysch3_zujian-inarea") > 0
        end)) do
            local card = Fk:getCardById(id)
            room:setCardMark(card, "@@ysch3_zujian-inarea", 0)
        end
        if bool1 then
            room:drawCards(tp,1,self.name)
        end
        if bool2 then
            room:drawCards(tp,1,self.name)
        end
        if bool1 and bool2 then
            room:useVirtualCard("savage_assault", nil, player, tp, self.name, true)
            --room:invalidateSkill(player, self.name, "-turn")
        end
    end
}
zhurong:addSkill(zujian)
if not Fk.skills["tanluan"] then
    local tanluan = fk.CreateTriggerSkill{
        name = "tanluan",
        anim_type = "control",
        events = {fk.TargetSpecified},
        can_trigger = function(self, event, target, player, data)
            if target == player and player:hasSkill(self) and data.firstTarget then
                local n = #player.room.alive_players - 2 * #AimGroup:getAllTargets(data.tos)
                if n <= 0 then
                self.cost_data = 1
                return #player.room:getPlayerById(data.to):getCardIds("ej") > 0
                else
                self.cost_data = 2
                return true
                end
            end
        end,
        on_cost = function(self, event, target, player, data)
            if self.cost_data == 1 then
                local targets = table.filter(AimGroup:getAllTargets(data.tos), function(id)
                return #player.room:getPlayerById(id):getCardIds("ej") > 0
                end)
                if #targets == 0 then return end
                local tos = player.room:askForChoosePlayers(player, targets, 1, 1, "#tanluan-choose", self.name, true)
                if #tos > 0 then
                self.cost_data = tos
                return true
                end
            else
                self.cost_data = 2
                return true
            end
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if type(self.cost_data) == "table" then
                local to = room:getPlayerById(self.cost_data[1])
                local cards = room:askForCardsChosen(player, to, 1, 1, "ej", self.name)
                room:throwCard(cards, self.name, to, player)
            else
                room:addPlayerMark(player, "@@tanluan-phase", 1)
            end
        end,
    }
    local tanluan_trigger = fk.CreateTriggerSkill{
        name = "#tanluan_trigger",
        mute = true,
        events = {fk.AfterCardUseDeclared, fk.AfterCardTargetDeclared},
        can_trigger = function(self, event, target, player, data)
            if target == player then
                if event == fk.AfterCardUseDeclared then
                return player:getMark("@@tanluan-phase") > 0
                else
                return data.extra_data and data.extra_data.tanluan and data.extra_data.tanluan[1] == player.id and
                    data.tos and #player.room:getUseExtraTargets(data) > 0
                end
            end
        end,
        on_cost = function (self, event, target, player, data)
            if event == fk.AfterCardUseDeclared then
                return true
            else
                local n = data.extra_data.tanluan[2]
                local tos = player.room:askForChoosePlayers(player, player.room:getUseExtraTargets(data), 1, n,
                "#tanluan-add:::"..data.card:toLogString()..":"..n, "tanluan", true)
                if #tos > 0 then
                self.cost_data = tos
                return true
                end
            end
        end,
        on_use = function(self, event, target, player, data)
            if event == fk.AfterCardUseDeclared then
                local n = player:getMark("@@tanluan-phase")
                player.room:setPlayerMark(player, "@@tanluan-phase", 0)
                data.extra_data = data.extra_data or {}
                data.extra_data.tanluan = {player.id, n}
            else
                table.insertTable(data.tos, table.map(self.cost_data, function(p) return {p} end))
            end
        end,
    }
    tanluan:addRelatedSkill(tanluan_trigger)
    Fk:addSkill(tanluan)
    Fk:loadTranslationTable{
        ["tanluan"] = "探乱",
        [":tanluan"] = "当你使用牌指定目标后，若目标角色数不少于非目标角色数，你可以弃置其中一名目标角色场上的一张牌；否则，"..
        "本回合你使用下一张牌目标数+1。",
        ["#tanluan-choose"] = "探乱：你可以弃置其中一名角色场上的一张牌",
        ["@@tanluan-phase"] = "探乱",
        ["#tanluan-add"] = "探乱：你可以为%arg额外指定%arg2个目标",
    }
end
zhurong:addSkill("tanluan")
Fk:loadTranslationTable{
    ["ysch3_zujian"] = "足践",
    [":ysch3_zujian"] = "出牌阶段每名角色限一次，你可以令一名其他角色交给你一张牌，然后再与其拼点，其每满足一项，便摸一张牌：你的拼点牌是其本次交给你的牌；其没赢。若均满足，视为对其使用【南蛮入侵】。",
    ["#ysch3_zujian"] = "足践：令一名其他角色交给你一张牌",
    ["@@ysch3_zujian-inarea"] = "足践",
    ["#ysch3_zujian-give"] = "足践：交给%src一张牌",

    ["$ysch3_zujian1"] = "看我如何灭你！哈哈哈哈哈哈！",
    ["$ysch3_zujian2"] = "看你等如何抵挡我这大象阵！哈哈哈哈哈哈！上！",
    ["$tanluan_ysch3__zhurong1"] = "哼！擒你，就如探囊取物！",
    ["$tanluan_ysch3__zhurong2"] = "哪里跑！",
}

local caozhi = General:new(extension, "ysch3__caozhi", "wei", 3, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__caozhi"] = "曹植",
    ["#ysch3__caozhi"] = "风流才子",
    ["designer:ysch3__caozhi"] = "铝",
    ["cv:ysch3__caozhi"] = "官方",
    ["illustrator:ysch3__caozhi"] = "地狱许",
}
local jiushi = fk.CreateActiveSkill{
    name = "ysch3_jiushi",
    prompt = "#ysch3_jiushi",
    mute = true,
    anim_type = "masochism",
    card_filter = function (self, to_select, selected, player)
        local card = Fk:getCardById(to_select)
        return (card.type == Card.TypeBasic or card:isCommonTrick()) and #selected == 0
    end,
    target_filter = function(self, to_select, selected, selected_cards, _, _, player)
        if #selected_cards > 0 then
            local card = Fk:getCardById(selected_cards[1])
            local tp = Fk:currentRoom():getPlayerById(to_select)
            if card.is_passive then
                return false
            elseif card.skill:getMinTargetNum() == 0 then
                if Util.AoeCanUse(card.skill,player,card) or Util.AoeCanUse(card.skill,tp,card) then
                    return true
                elseif Util.GlobalCanUse(card.skill,player,card) or Util.GlobalCanUs(card.skill,tp,card) then
                    return true
                else
                    return #selected == 0
                end
            else
                return true
                --return card.skill:targetFilter(to_select, {}, {}, card, {bypass_times = true,bypass_distances = true}, player) or card.skill:targetFilter(player.id, {}, {}, card, {bypass_times = true,bypass_distances = true}, tp)
            end
        end
    end,
    target_tip = function (self, to_select, selected, selected_cards, card, selectable, extra_data)
        if #selected_cards > 0 then
            local card = Fk:getCardById(selected_cards[1])
            local tp = Fk:currentRoom():getPlayerById(to_select)
            if Self:canUseTo(card,tp,{bypass_times = false,bypass_distances = false}) then
                return "@ysch3_jiushi"
            end
        end
    end,
    feasible = function (self, selected, selected_cards, player)
        if #selected_cards > 0 then
            local card = Fk:getCardById(selected_cards[1])
            if card.is_passive then
                return #selected == 0
            elseif card.skill:getMinTargetNum() == 0 then
                if #selected > 0 then
                    local tp = Fk:currentRoom():getPlayerById(selected[1])
                    if Util.AoeCanUse(card.skill,player,card) or Util.AoeCanUse(card.skill,tp,card) then
                        return true
                    elseif Util.GlobalCanUse(card.skill,player,card) or Util.GlobalCanUs(card.skill,tp,card) then
                        return true
                    else
                        return #selected == 1
                    end
                else
                    return false
                end
            else
                local targets = table.filter(Fk:currentRoom().alive_players, function (p)
                    return card.skill:targetFilter(p.id, {}, {}, card, {bypass_times = true,bypass_distances = true}, player)
                end)
                if #targets > 0 then
                    return #selected <= card.skill:getMaxTargetNum(Self, card) and #selected >= card.skill:getMinTargetNum()
                else
                    return #selected == 0
                end
            end
        else
            return false
        end
    end,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        local tos = effect.tos
        local card = Fk:getCardById(effect.cards[1])
        local legal = true
        local anim_type = table.random({"special","drawcard","control","offensive","support","defensive","negative","masochism","switch"})
        room:notifySkillInvoked(player,self.name,anim_type)
        player:broadcastSkillInvoke(self.name)
        if #tos == 0 then
            if card.skill:getMinTargetNum() == 0 then
                if card.is_passive or card.trueName == "collateral" then
                  --
                elseif card.multiple_targets then
                    local use = {
                        from = player.id,
                        card = Fk:cloneCard(card.name),
                        tos = {},
                    }
                    card.skill:onUse(room, use)
                    tos = table.simpleClone(TargetGroup:getRealTargets(use.tos))
                else
                    if player:canUse(card, {bypass_times = true,bypass_distances = true}) then
                        tos = {player.id}
                    end
                end
            end
            if #tos == 0 then
                if #room.alive_players == 0 then
                    return
                else
                    tos = table.map(room:getAlivePlayers(), Util.IdMapper)
                end
            end
        end
        room:sortPlayersByAction(tos)

        for _, id in ipairs(tos) do
            if player:canUseTo(card,room:getPlayerById(id),{bypass_times = false,bypass_distances = false}) ~= true then
                legal = false
                break
            end
        end
        card.skillName = self.name
        room:useCard{
            from = player.id,
            tos = table.map(tos, function (id)
                return {id}
            end),
            card = card,
        }
        player:drawCards(1,self.name)
        if legal == false then
            local result = room:askForSkillInvoke(player,self.name,nil,"#ysch3_jiushi-legal")
            if result == true then
                room:loseHp(player, 1, self.name)
            else
                room:endTurn()
            end
        end
    end,
}
caozhi:addSkill(jiushi)
Fk:loadTranslationTable{
    ["ysch3_jiushi"] = "酒诗",
    [":ysch3_jiushi"] = "出牌阶段，你可以使用一张即时牌再摸一张牌，若不合法，你失去1点体力或结束此回合。",
    ["#ysch3_jiushi"] = "酒诗：你可以使用一张即时牌",
    ["#ysch3_jiushi-legal"] = "酒诗：失去1点体力，或点“取消”结束此回合",
    ["@ysch3_jiushi"] = "合法目标",

    ["$ysch3_jiushi1"] = "置酒高殿上，亲友从我游。",
    ["$ysch3_jiushi2"] = "走马行酒醴，驱车布鱼肉。",
}
--[[
local jushou = General(extension, "steam__jushou", "qun", 3)
jushou.total_hidden = true
local jianying = fk.CreateViewAsSkill{
    name = "steam__jianying",
    prompt = "#steam__jianying-active",
    interaction = function()
        local names, all_names = {} , {}
        for _, id in ipairs(Fk:getAllCardIds()) do
            local card = Fk:getCardById(id)
            if card.type == Card.TypeBasic and not card.is_derived and not table.contains(all_names, card.name) then
            table.insert(all_names, card.name)
            local to_use = Fk:cloneCard(card.name)
            if Self:canUse(to_use) and not Self:prohibitUse(to_use) then
                table.insert(names, card.name)
            end
            end
        end
        if #names == 0 then return false end
        return U.CardNameBox { choices = names, all_choices = all_names }
    end,
    card_filter = function(self, to_select, selected)
        return #selected == 0
    end,
    before_use = function(self, player, use)
        player.room:setPlayerMark(player, "steam__jianying-used-phase", 1)
    end,
    view_as = function(self, cards)
        if not self.interaction.data or #cards ~= 1 then return end
        local card = Fk:cloneCard(self.interaction.data)
        card:addSubcards(cards)
    
        local suitstrings = {"spade", "heart", "club", "diamond"}
        local suits = {Card.Spade, Card.Heart, Card.Club, Card.Diamond}
        local colors = {Card.Black, Card.Red, Card.Black, Card.Diamond}
        local suit = Self:getMark("steam__jianying_suit")
        if table.contains(suitstrings, suit) then
            card.suit = suits[table.indexOf(suitstrings, suit)]
            card.color = colors[table.indexOf(suitstrings, suit)]
        end
    
        card.skillName = self.name
        return card
    end,
    enabled_at_play = function(self, player)
        return player:getMark("steam__jianying-used-phase") == 0
    end,
}
local jianying_trigger = fk.CreateTriggerSkill{
    name = "#steam__jianying_trigger",
    mute = true,
    anim_type = "drawcard",
    events = {fk.CardUsing},
    can_trigger = function(self, event, target, player, data)
        if player ~= target or not player:hasSkill(self) then return false end
        local room = player.room
        local logic = room.logic
        local use_event = logic:getCurrentEvent()
        local events = logic.event_recorder[GameEvent.UseCard] or Util.DummyTable
        local last_find = false
        for i = #events, 1, -1 do
        local e = events[i]
        if e.data[1].from == player.id then
            if e.id == use_event.id then
            last_find = true
            elseif last_find then
            local last_use = e.data[1]
            return data.card:compareSuitWith(last_use.card) or data.card:compareNumberWith(last_use.card)
            end
        end
        end
    end,
    on_use = function(self, event, target, player, data)
        player.room:notifySkillInvoked(player,self.name,"drawcard")
        player:broadcastSkillInvoke("steam__jianying")
        player:drawCards(1, self.name)
    end,

    refresh_events = {fk.AfterCardUseDeclared, fk.EventLoseSkill},
    can_refresh = function(self, event, target, player, data)
        if event == fk.AfterCardUseDeclared then
        return target == player and player:hasSkill(self, true)
        elseif event == fk.EventLoseSkill then
        return data == self
        end
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        if event == fk.AfterCardUseDeclared then
            if data.card.suit == Card.NoSuit then
                room:setPlayerMark(player, "steam__jianying_suit", 0)
            else
                room:setPlayerMark(player, "steam__jianying_suit", data.card:getSuitString())
            end
            room:setPlayerMark(player, "@steam__jianying", {data.card:getSuitString(true), data.card:getNumberStr()})
        else if event == fk.EventLoseSkill then
            room:setPlayerMark(player, "steam__jianying_suit", 0)
                room:setPlayerMark(player, "@steam__jianying", 0)
            end
        end
    end,
}
jianying:addRelatedSkill(jianying_trigger)
local shibei = fk.CreateTriggerSkill{
    name = "steam__shibei",
    mute = true,
    anim_type = "defensive",
    frequency = Skill.Compulsory,
    events = {fk.Damaged},
    can_trigger = function(self, event, target, player, data)
        if target ~= player or not player:hasSkill(self) then return false end
        local room = player.room
        local damage_event = room.logic:getCurrentEvent()
        local mark = player:getMark("steam__shibei_record-turn")
        if type(mark) ~= "table" then
        mark = {}
        end
        if #mark < 2 and not table.contains(mark, damage_event.id) then
        local damage_ids = {}
        room.logic:getEventsOfScope(GameEvent.ChangeHp, 2, function (e)
            if e.data[1] == player and e.data[3] == "damage" then
            local first_damage_event = e:findParent(GameEvent.Damage)
            if first_damage_event then
                table.insert(damage_ids, first_damage_event.id)
                return true
            end
            end
            return false
        end, Player.HistoryTurn)
        if #damage_ids > #mark then
            mark = damage_ids
            room:setPlayerMark(player, "steam__shibei_record-turn", mark)
        end
        end
        return table.contains(mark, damage_event.id) and not (mark[1] == damage_event.id and not player:isWounded())
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local mark = player:getMark("steam__shibei_record-turn")
        if type(mark) ~= "table" or #mark == 0 then return false end
        local damage_event = room.logic:getCurrentEvent():findParent(GameEvent.Damage, true)
        if not damage_event then return false end
        if mark[1] == damage_event.id then
        player:broadcastSkillInvoke(self.name, 1)
        room:notifySkillInvoked(player, self.name)
        room:recover{
            who = player,
            num = 1,
            skillName = self.name
        }
        end
        if #mark > 1 and mark[2] == damage_event.id then
        player:broadcastSkillInvoke(self.name, 2)
        room:notifySkillInvoked(player, self.name, "negative")
        room:loseHp(player, 1, self.name)
        end
    end,
}
local hongli = fk.CreateTriggerSkill{
    name = "#steam__hongli",
    mute = true,
    frequency = Skill.Compulsory,
    events = {fk.BeforeDrawCard},
    priority = 0.005,
    can_trigger = function (self, event, target, player, data)
      return player:hasSkill(self) and target == player and data.num > 0
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local cid
        -- 找元戎精械弩
        if player.phase == Player.Draw and not table.find(player:getCardIds("he"), function (id)
            return table.contains({"ex_crossbow","ysch_Al__crossbow"},Fk:getCardById(id).name)
        end) then
            cid = table.find(room.draw_pile, function (id) return table.contains({"ex_crossbow","ysch_Al__crossbow"},Fk:getCardById(id).name) end)
            if cid then
                table.removeOne(room.draw_pile, cid)
                table.insert(room.draw_pile, 1, cid)
                room:syncDrawPile()
            end
            if not cid then
                cid = table.find(room.void, function (id) return table.contains({"ex_crossbow","ysch_Al__crossbow"},Fk:getCardById(id).name) end)
                if cid then
                    room:moveCardTo(cid, Card.DrawPile, nil, fk.ReasonPut, self.name, nil, false, player.id)
                end
            end
            if cid then
                --player:broadcastSkillInvoke(self.name) 隐藏的播不了
                room:broadcastPlaySound("./packages/"..extension.extensionName.."/audio/skill/steam__hongli")
                room:notifySkillInvoked(player, self.name, "drawcard")
                return
            end
        end
        -- 找无中，或者忠胆版无中
        cid = table.find(room.draw_pile, function (id) return table.contains({"reinforcement", "ex_nihilo"}, Fk:getCardById(id).name) end)
        -- 如果自己没AK，再找1把
        if not cid and not table.find(player:getCardIds("he"), function (id)
            return table.contains({"crossbow", "xbow"}, Fk:getCardById(id).name)
        end) then
            cid = table.find(room.draw_pile, function (id) return table.contains({"crossbow", "xbow"}, Fk:getCardById(id).name) end)
        end
        -- 啥都有了，找点好牌
        if not cid then
            local mark = player:getMark("@steam__jianying-phase")
            local fitJianying = function (card)
                return mark == 0 or (card.number == mark[2] or card:getSuitString(true) == mark[1])
            end
            cid = table.find(room.draw_pile, function (id)
                local c = Fk:getCardById(id)
                return (fitJianying(c) or math.random() < 0.4) and (
                (c.name == "peach" and player:isWounded())
                or (c.type == Card.TypeTrick and not c.is_passive)
                or (c.trueName == "slash" and player:canUse(c) and math.random() < 0.4)
                )
            end)
        end
        if cid then
            table.removeOne(room.draw_pile, cid)
            table.insert(room.draw_pile, 1, cid)
            room:syncDrawPile()
        end
    end,
}
jushou:addSkill(jianying)
jushou:addSkill(shibei)
jushou:addSkill(hongli)
Fk:loadTranslationTable{
    ["steam__jianying"] = "渐营",
    ["#steam__jianying_trigger"] = "渐营",
    [":steam__jianying"] = "当你使用牌时，若此牌与你使用的上一张牌点数或花色相同，你可以摸一张牌。出牌阶段限一次，你可以将一张牌当任意一种基本牌使用，若你使用的上一张牌有花色，则此牌花色视为你使用的上一张牌的花色。",
    ["#steam__jianying-active"] = "发动渐营，将一张牌转化为任意基本牌使用",
    ["steam__shibei"] = "矢北",
    [":steam__shibei"] = "锁定技，当你受到伤害后，若此次伤害：是你本回合受到的第一次伤害，你回复1点体力；是你本回合受到的第二次伤害，你失去1点体力。",
    ["@steam__jianying"] = "渐营",
    ["#steam__hongli"] = "红利",
    [":#steam__hongli"] = "锁定技，摸牌阶段，你发明【元戎精械弩】。当你摸牌前，将牌堆的【无中生有】、伤害锦囊牌或符合你“渐营”的可用牌置顶。",
    --偷偷修改一下扶摇的沮授
    ["$steam__jianying_audio1"] = "良谋百出，渐定决战胜势！",
    ["$steam__jianying_audio2"] = "佳策数成，破敌垂手可得！",
    ["$steam__shibei_audio1"] = "只有杀身士，绝无降曹夫！",
    ["$steam__shibei_audio2"] = "心向袁氏，绝无背离可言！",
    ["$steam__hongli"] = "得胜已是定局，何必急功近利？",
}]]--
local wangxiang = General:new(extension, "ysch3__wangxiang", "jin", 4, 4, General.Male)--
wangxiang.total_hidden = true
Fk:loadTranslationTable{
    ["ysch3__wangxiang"] = "王祥",
    ["#ysch3__wangxiang"] = "极寒风暴",
    ["designer:ysch3__wangxiang"] = "铝",
    ["cv:ysch3__wangxiang"] = "未知",
    ["illustrator:ysch3__wangxiang"] = "M云涯",
}
local bingxin = fk.CreateTriggerSkill{
    name = "ysch3_bingxin",
    anim_type = "masochism",
    events = {fk.DamageInflicted},
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(self.name) then
            return data.damage > (player.hp/10) and player:getMark("@@ysch3_bingxin_cd-turn") == 0
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local damageType = table.random({fk.FireDamage,fk.ThunderDamage,fk.IceDamage},1)[1]
        local targets = {}
        room:setPlayerMark(player,"@@ysch3_bingxin_cd-turn",1)
        for _, p in ipairs(room:getAlivePlayers()) do
            if player:distanceTo(p) < 2 and not p:isRemoved() and p ~= player then
                room:doIndicate(player.id, {p.id})
                room:setPlayerMark(p,"@@ysch3_bingxin_effect-turn",1)
                table.insert(targets,p)
            end
        end
        for _, p in ipairs(targets) do
            room:damage{
                from = player,
                to = p,
                damage = 1,
                damageType = damageType,
                skillName = self.name,
            }
        end
        room:animDelay(2)

        room:setPlayerMark(player,"@@ysch3_bingxin_cd-turn",0)
        for _, p in ipairs(room:getAlivePlayers()) do
            if player:distanceTo(p) < 2 and not p:isRemoved() and p ~= player then
                room:setPlayerMark(p,"@@ysch3_bingxin_effect-turn",0)
            end
        end
    end,
}
local bingxin_prohibit = fk.CreateProhibitSkill{
    name = "#ysch3_bingxin_prohibit",
    prohibit_use = function(self, player, card)
      return card and player:getMark("@@ysch3_bingxin_effect-turn") > 0
    end,
}
bingxin:addRelatedSkill(bingxin_prohibit)
wangxiang:addSkill(bingxin)
Fk:loadTranslationTable{
    ["ysch3_bingxin"] = "冰心",
    [":ysch3_bingxin"] = "<br>+20%<font color=#387c14>冷却缩减</font> +500<font color=#5f3287>最大法力</font> +360<font color=#dc5022>物理防御</font><br>受到伤害超过体力值10%时，发射<a href='ysch3_hanbingchongji'>寒冰冲击</a>，对范围内敌人造成1点<font color=#0a5ad2>法术伤害</font>，降低范围内敌人15%攻速和30%移速，持续2秒。（◔2秒）",
    ["ysch3_hanbingchongji"] = "对距离1以内的其他角色造成随机一种属性伤害，并令其2秒内不能使用牌",
    ["@@ysch3_bingxin_cd-turn"] = "<font color=#cacaca>冰心 CD中</font>",
    ["@@ysch3_bingxin_effect-turn"] = "<font color=#75baff>被减速 冰心</font>",

    ["$ysch3_bingxin1"] = "卧槽，冰！",
    ["$ysch3_bingxin2"] = "冰心一出，游戏结束",
    ["~ysch3__wangxiang"] = "夫生之有死，自然之理也。",
}
local libai = General:new(extension, "ysch3__libai", "tang", 3, 3, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__libai"] = "李白",
    ["#ysch3__libai"] = "青莲居士",
    ["designer:ysch3__libai"] = "铝",
    ["cv:ysch3__libai"] = "官方",
    ["illustrator:ysch3__libai"] = "珊瑚虫",

    ["tang"] = "唐",
}
local miaobi = fk.CreateViewAsSkill{
    name = "ysch3_miaobi",
    pattern = ".",
    prompt = "#ysch3_miaobi",
    dynamic_desc = function(self, player)
        local n = math.random()
        if n > 0.6 then
            return "ysch3_miaobi"
        else if n > 0.3 then
                return "ysch3_miaobi2"
            else
                return "ysch3_miaobi3"
            end
        end
    end,
    interaction = function()
        local names, all_names = {}, {}
        for _, id in ipairs(Fk:getAllCardIds()) do
            local card = Fk:getCardById(id)
            if (card.type == Card.TypeBasic or card:isCommonTrick()) and not card.is_derived then
                table.insertIfNeed(all_names, card.name)
                local to_use = Fk:cloneCard(card.name)
                if ((Fk.currentResponsePattern == nil and Self:canUse(to_use) and not Self:prohibitUse(to_use)) or
                    (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use))) then
                    table.insertIfNeed(names, card.name)
                end
            end
        end
        if #names == 0 then return false end
        return U.CardNameBox { choices = names, all_choices = all_names }
    end,
    view_as = function(self, cards)
        if not self.interaction.data then return end
        local card = Fk:cloneCard(self.interaction.data)
        card.skillName = self.name
        return card
    end,
    before_use = function(self, player, use)
        local room = player.room
        local bool = false
        local result = room:askForGuanxing(player, room:getNCards(4), nil, nil, self.name)
        local bottom = result.bottom
        if bottom ~= nil then
            for _, id in ipairs(bottom) do
                local card = Fk:getCardById(id)
                if card.suit == Card.Spade then
                    bool = true
                    break 
                end
            end
        end
        p(bool == false)
        if bool == false then
            return ""
        end
    end,
    enabled_at_play = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryTurn) < 1
    end,
    enabled_at_response = function(self, player, response)
        return player:usedSkillTimes(self.name, Player.HistoryTurn) < 1
    end,
}
libai:addSkill(miaobi)
Fk:loadTranslationTable{
    ["ysch3_miaobi"] = "妙笔",
    [":ysch3_miaobi"] = "<br>视 如 你 若<br>为 置 可 需 回<br>使 黑 卜 用 合<br>用 桃 算 即 技<br>之 底 四 时"..
    "<br><br> <font color='#a40000'><a href='ysch3_miaobi-true'>大鹏一日同风起，扶摇直上九万里</a></font>",
    [":ysch3_miaobi2"] = "<br>凭 置 坐 真<br>空 底 卜 到 回<br>便 若 再 君<br>能 有 三 用 合<br>巧 黑 亦 即<br>运 桃 不 时 技<br>之 匿 迟 处"..
    "<br><br> <font color='#a40000'><a href='ysch3_miaobi-true'>兴酣落笔摇五岳，诗成笑傲凌沧洲</a></font>",
    [":ysch3_miaobi3"] = "<br>信 若 慎 临<br>手 得 算 机 回<br>拈 渊 三 决<br>来 中 番 断 合<br>化 藏 未 正<br>奇 玄 为 当 技<br>施 妙 迟 时"..
    "<br><br> <font color='#a40000'><a href='ysch3_miaobi-true'>青莲居士谪仙人，酒肆藏名三十春</a></font>",
    ["#ysch3_miaobi"] = "妙笔：卜算4，若将♠牌置入牌堆底，视为使用你所需的即时牌",
    ["ysch3_miaobi-true"] = "<b>妙笔</b>：每回合限一次，当你需要使用即时牌时，你可以卜算4，若将♠牌置于牌堆底，视为使用所需牌。",

    ["$ysch3_miaobi1"] = "武侯立岷蜀，壮志吞咸京。",
    ["$ysch3_miaobi2"] = "鱼水三顾合，风云四海生。",
    ["~ysch3__libai"] = "谁识卧龙客，长吟愁鬓斑。",
}
local zhugedan = General:new(extension, "ysch3__zhugedan", "wei", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__zhugedan"] = "诸葛诞",
    ["#ysch3__zhugedan"] = "居功尽瘁",
    ["designer:ysch3__zhugedan"] = "铝&cyc",
    ["cv:ysch3__zhugedan"] = "官方",
    ["illustrator:ysch3__zhugedan"] = "匠人绘",
}
local gongao = fk.CreateTriggerSkill{
    name = "ysch3_gongao",
    mute = true,
    events = {fk.EnterDying},
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) then
        local dying_id = target:getMark(self.name)
        local cur_event = player.room.logic:getCurrentEvent()
        if dying_id ~= 0 then
            return cur_event.id == dying_id
        else
            local events = player.room.logic.event_recorder[GameEvent.Dying] or Util.DummyTable
            local canInvoke = true
            for i = #events, 1, -1 do
            local e = events[i]
            if e.data[1].who == target.id and e.id ~= cur_event.id then
                canInvoke = false
                break
            end
            end
            if canInvoke then
            player.room:setPlayerMark(target, self.name, cur_event.id)
            return true
            end
        end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local choices , all_choices = {},{"phase_start","phase_judge","phase_draw","phase_play","phase_discard","phase_finish","Cancel"}
        for _, v in ipairs(all_choices) do
            if player:getMark("ysch3_gongao_phase") == 0 or not table.contains(player:getMark("ysch3_gongao_phase"),v) then
                table.insert(choices,v)
            end
        end
        local str = "功獒：获得一个额外回合，或为额外回合加入一个尚无的阶段"
        if data.damage and data.damage.from and data.damage.from.id == player.id then
            str = "功獒：获得一个额外回合，并为额外回合加入一个尚无的阶段"
            table.removeOne(choices,"Cancel")
            table.removeOne(all_choices,"Cancel")
        end
        self.cost_data = "Cancel"
        if ( player:getMark("ysch3_gongao_turn") > 0 or data.damage and data.damage.from and data.damage.from.id == player.id ) and #choices > 1 then
            local result = room:askForChoice(player,choices,self.name,str,false,all_choices)
            if result ~= "Cancel" then
                self.cost_data = result
            end
        end
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local turns = {"phase_start","phase_judge","phase_draw","phase_play","phase_discard","phase_finish"}
        local arr = type(player:getMark("ysch3_gongao_phase")) == "table" and player:getMark("ysch3_gongao_phase") or {}
        if self.cost_data == "Cancel" or data.damage and data.damage.from and data.damage.from.id == player.id then
            room:addPlayerMark(player,"ysch3_gongao_turn",1)
        end
        local str = "x"..tostring(player:getMark("ysch3_gongao_turn")).." "
        for _, v in ipairs(turns) do
            if v == self.cost_data then
                table.insert(arr,v)
                table.sort(arr,function (a, b)
                    return Util.PhaseStrMapper(a) < Util.PhaseStrMapper(b)
                end)
            end
            if table.contains(arr,v) then
                str = str..Fk:translate("ysch3_"..v)
            end
        end
        room:notifySkillInvoked(player,self.name,"support")
        player:broadcastSkillInvoke(self.name,math.random(1,2))
        room:setPlayerMark(player,"ysch3_gongao_phase",arr)
        room:setPlayerMark(player,"@ysch3_gongao",str)
    end,
}
local gongao_turn = fk.CreateTriggerSkill{
    name = "#ysch3_gongao_turn",
    frequency = Skill.Compulsory,
    anim_type = "offensive",
    events = {fk.RoundEnd,fk.TurnEnd},
    can_trigger = function (self, event, target, player, data)
        if event == fk.TurnEnd then
            if target ~= player or player:getCurrentExtraTurnReason() ~= "ysch3_gongao" then
                return false
            end
        end
        return player:usedSkillTimes(self.name, Player.HistoryRound) < player:getMark("ysch3_gongao_turn")
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local phaseList = type(player:getMark("ysch3_gongao_phase")) == "table" and player:getMark("ysch3_gongao_phase") or {}
        player:broadcastSkillInvoke("ysch3_gongao",3)
        table.insertTable(phaseList,{Player.RoundStart,Player.PhaseNone})
        player:gainAnExtraTurn(true, "ysch3_gongao",{ phase_table = table.map(phaseList, Util.PhaseStrMapper) })
    end,
}
gongao_turn.permanent_skill = true
gongao:addRelatedSkill(gongao_turn)
zhugedan:addSkill(gongao)
local juyi = fk.CreateTriggerSkill{
    name = "ysch3_juyi",
    mute = true,
    anim_type = "drawcard",
    events = {fk.EventPhaseEnd},
    dynamic_desc = function(self, player)
        if type(player:getMark("ysch3_juyi_phase")) == "table" then
            return "ysch3_juyi2"
        else
            return "ysch3_juyi"
        end
    end,
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(self) then
            return table.contains({Player.Judge,Player.Draw,Player.Play,Player.Discard},player.phase) and (type(player:getMark("ysch3_juyi_phase")) ~= "table" or not table.contains(player:getMark("ysch3_juyi_phase"), player.phase))
        end
    end,
    on_cost = function (self, event, target, player, data)
        if type(player:getMark("ysch3_juyi_phase")) ~= "table" then
            local arr = type(player:getMark("ysch3_juyi_phase")) == "table" and player:getMark("ysch3_juyi_phase") or {}
            return player.room:askForSkillInvoke(player, self.name, nil, "#ysch3_juyi-invoke:::"..Fk:translate(Util.PhaseStrMapper(player.phase))..":"..(#arr+1))
        else
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local arr = type(player:getMark("ysch3_juyi_phase")) == "table" and player:getMark("ysch3_juyi_phase") or {}
        local turns = {"turn_start","phase_start","phase_judge","phase_draw","phase_play","phase_discard","phase_finish","turn_finish"}
        local str = "<font color=#cacaca><s>"
        table.insert(arr,player.phase)
        table.sort(arr)
        for _, v in ipairs(arr) do
            str = str..Fk:translate("ysch3_"..turns[v])
        end
        room:notifySkillInvoked(player,self.name,"drawcard")
        player:broadcastSkillInvoke(self.name,math.random(1,2))
        room:setPlayerMark(player,"ysch3_juyi_phase",arr)
        room:setPlayerMark(player,"@ysch3_juyi",str.."</s></font>")
        room:drawCards(player,#arr,self.name)
    end,
}
local juyi_phase = fk.CreateTriggerSkill{
    name = "#ysch3_juyi_phase",
    frequency = Skill.Compulsory,
    mute = true,
    events = {fk.EventPhaseChanging},
    can_trigger = function(self, event, target, player, data)
        if target == player and not player:insideExtraTurn() and type(player:getMark("ysch3_juyi_phase")) == "table" and data.to > 2 and data.to < 7 then
            return table.contains(player:getMark("ysch3_juyi_phase"), data.to)
        end
    end,
    on_use = function (self, event, target, player, data)
        if player:usedSkillTimes(self.name, Player.HistoryTurn) == 1 then
            player:broadcastSkillInvoke("ysch3_juyi",3)
        end
        return true
    end,
}
juyi_phase.permanent_skill = true
juyi:addRelatedSkill(juyi_phase)
zhugedan:addSkill(juyi)
Fk:loadTranslationTable{
    ["ysch3_gongao"] = "功獒",
    [":ysch3_gongao"] = "一名角色首次濒死时，你获得一个每轮结束时执行的无阶段回合，或为以此法获得的回合加入一个尚无的阶段。背水:伤害来源为你。",
    ["@ysch3_gongao"] = "功獒",
    ["#ysch3_gongao_turn"] = "功獒",
    ["ysch3_phase_start"] = "准",
    ["ysch3_phase_judge"] = "判",
    ["ysch3_phase_draw"] = "摸",
    ["ysch3_phase_play"] = "出",
    ["ysch3_phase_discard"] = "弃",
    ["ysch3_phase_finish"] = "结",
    ["ysch3_juyi"] = "举义",
    [":ysch3_juyi"] = "主要阶段结束时，你可以删除“可以”和额定回合的该阶段，然后摸X张牌。（X为你已删除阶段数+1）",
    [":ysch3_juyi2"] = "主要阶段结束时，你删除额定回合的该阶段，然后摸X张牌。（X为你已删除阶段数+1）",
    ["#ysch3_juyi-invoke"] = "举义：是否删除额定回合的%arg，然后摸%arg2张牌",
    ["@ysch3_juyi"] = "<font color=#cacaca>举义</font>",

    ["$ysch3_gongao1"] = "攻城拔寨，建功立业。",
    ["$ysch3_gongao2"] = "恪尽职守，忠心事主。",
    ["$ysch3_gongao3"] = "若国有难，吾当举义。",
    ["$ysch3_juyi1"] = "司马氏篡权，我当替天伐之！",
    ["$ysch3_juyi2"] = "定当夷司马氏三族！",
    ["$ysch3_juyi3"] = "咳……咳咳……",
    ["~ysch3__zhugedan"] = "诸葛一氏定会为我复仇！",
}
local sunjun = General:new(extension, "ysch3__sunjun", "wu", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__sunjun"] = "孙峻",
    ["#ysch3__sunjun"] = "朋党执虎",
    ["designer:ysch3__sunjun"] = "铝&汤圆",
    ["cv:ysch3__sunjun"] = "佚名",
    ["illustrator:ysch3__sunjun"] = "鬼画府",
}
local bazheng = fk.CreateTriggerSkill{
    name = "ysch3_bazheng",
    frequency = Skill.Compulsory,
    anim_type = "offensive",
    attached_skill_name = "ysch3_quanji",
    events = {fk.TargetSpecified,fk.TurnEnd},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) then
            if event == fk.TargetSpecified then
                local to = player.room:getPlayerById(data.to)
                return player.phase ~= Player.NotActive and data.to ~= player.id and data.card.trueName == "slash" and #to:getPile("ysch3__zhonghui_power") > 0
            else if event == fk.TurnEnd then
                    return player ~= target and #target:getPile("ysch3__zhonghui_power") > #player.room.alive_players
                end
            end
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if event == fk.TargetSpecified then
            data.disresponsive = true
        else
            room:killPlayer({who = target.id})
        end
    end,

    refresh_events = {fk.Deathed},
    can_refresh = function (self, event, target, player, data)
        return target == player and #table.filter(Fk:currentRoom().alive_players, function(p) return p:hasSkill(self.name) and p ~= player end) == 0
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        for _, p in ipairs(room.alive_players) do
            local quan = p:getPile("ysch3__zhonghui_power")
            if #quan > 0 then
                room:throwCard(quan, self.name, p, p)
            end
        end
    end,
}
sunjun:addSkill(bazheng)
local quanji = fk.CreateTriggerSkill{
    name = "ysch3_quanji",
    anim_type = "masochism",
    derived_piles = "ysch3__zhonghui_power",
    events = {fk.Damaged, fk.EventPhaseEnd},
    can_trigger = function(self, event, target, player, data)
        return target == player and table.find(Fk:currentRoom().alive_players, function (p)
            return p:hasSkill(bazheng)
        end) and player:hasSkill(self) and
        (event == fk.Damaged or (player.phase == Player.Play and player:getHandcardNum() > player.hp))
    end,
    on_trigger = function(self, event, target, player, data)
        local x = (event == fk.Damaged) and data.damage or 1
        self.cancel_cost = false
        for i = 1, x do
        if self.cancel_cost or not player:hasSkill(self) then break end
        self:doCost(event, target, player, data)
        end
    end,
    on_cost = function(self, event, target, player, data)
        if player.room:askForSkillInvoke(player, self.name, data) then
            return true
        end
        self.cancel_cost = true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        player:drawCards(1, self.name)
        if not (player.dead or player:isKongcheng()) then
        local card = room:askForCard(player, 1, 1, false, self.name, false, nil, "#ysch3_quanji-push")
        player:addToPile("ysch3__zhonghui_power", card, true, self.name)
        end
    end,
}
local quanji_maxcards = fk.CreateMaxCardsSkill{
    name = "#ysch3_quanji_maxcards",
    correct_func = function(self, player)
        if table.find(Fk:currentRoom().alive_players, function (p)
            return p:hasSkill(bazheng)
        end) and player:hasSkill(quanji) then
        return #player:getPile("ysch3__zhonghui_power")
        else
        return 0
        end
    end,
}
quanji:addRelatedSkill(quanji_maxcards)
bazheng:addRelatedSkill(quanji)
sunjun:addRelatedSkill(quanji)
local shanzhi = fk.CreateTriggerSkill{
    name = "ysch3_shanzhi",
    anim_type = "offensive",
    events = {fk.AfterCardTargetDeclared},
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(self) and #TargetGroup:getRealTargets(data.tos) == 1 and
        data.card.is_damage_card then
            local room = player.room
            local to = room:getPlayerById(data.tos[1][1])
            local cards1,cards2 = 0,0
            for _, ids in pairs(player.special_cards) do
                cards1 = cards1 + #ids
            end
            for _, ids in pairs(to.special_cards) do
                cards2 = cards2 + #ids
            end
            local n = math.abs(cards1-cards2)
            return n > 0
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local to = room:getPlayerById(data.tos[1][1])
        local cards1,cards2 = 0,0
        for _, ids in pairs(player.special_cards) do
            cards1 = cards1 + #ids
        end
        for _, ids in pairs(to.special_cards) do
            cards2 = cards2 + #ids
        end
        local n = math.abs(cards1-cards2)
        if player.room:askForSkillInvoke(player, self.name, nil, "#ysch3_shanzhi::"..to.id..":"..n) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = room:getPlayerById(data.tos[1][1])
        local cards1,cards2 = 0,0
        for _, ids in pairs(player.special_cards) do
            cards1 = cards1 + #ids
        end
        for _, ids in pairs(to.special_cards) do
            cards2 = cards2 + #ids
        end
        local n = math.abs(cards1-cards2)
        --for i = 1, n, 1 do
            local choices, all_choices = {}, {"#ysch3_shanzhi-choice1::"..player.id,"#ysch3_shanzhi-choice2:::"..data.card:toLogString(),"#ysch3_shanzhi-choice3::"..player.id}
            if not to:isNude() then
                table.insert(choices,"#ysch3_shanzhi-choice1::"..player.id)
            end
            table.insert(choices,"#ysch3_shanzhi-choice2:::"..data.card:toLogString())
            local targets = {}
            if #table.filter(room.alive_players, function (tp)
                if #tp:getPile("ysch3__zhonghui_power") > 0 then
                    table.insert(targets,tp)
                    return true
                end
            end) > 0 then
                table.insert(choices,"#ysch3_shanzhi-choice3::"..player.id)
            end
            local result = room:askForChoices(to,choices,math.min(n,3,#choices),math.min(n,3,#choices),self.name,nil,false,false,all_choices)
            local new_result = {}
            for _, v in ipairs(result) do
                table.insert(new_result,string.sub(v,22,22))
            end
            if table.contains(new_result,"1") then
                local card = room:askForCard(to, 1, 1, true, self.name, false, ".", "#ysch3_shanzhi-choice1::"..player.id)
                if #card > 0 then
                    room:moveCardTo(Fk:getCardById(card[1]), Card.PlayerHand, player, fk.ReasonGive, self.name, nil, false, target.id)
                end
            end
            if table.contains(new_result,"2") then
                data.additionalDamage = (data.additionalDamage or 0) + 1
            end
            if table.contains(new_result,"3") then
                local moves = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#ysch3_shanzhi-choice0", self.name, false)
                if #moves > 0 then
                    local moveFrom = room:getPlayerById(moves[1])
                    local moveCards = room:askForCardsChosen(player,moveFrom,1,1,{card_data = {{"权",moveFrom:getPile("ysch3__zhonghui_power")}}},self.name,"#ysch3_shanzhi-choice0")
                    if #moveCards then
                        local move = room:askForChoosePlayers(player, table.map(table.filter(room.alive_players,function (p)
                            return p.id ~= moveFrom.id
                        end), Util.IdMapper), 1, 1, "#ysch3_shanzhi-choice0", self.name, false)
                        if #move then
                            local moveTo = room:getPlayerById(move[1])
                            local quan = Fk:getCardById(moveCards[1])
                            --room:moveCardTo(quan, Card.PlayerSpecial, moveTo, fk.ReasonJustMove, self.name, "ysch3__zhonghui_power", true, player.id, nil, nil)
                            moveTo:addToPile("ysch3__zhonghui_power", quan, true, self.name)
                        end
                    end
                end
            end
        --end
    end,
}
sunjun:addSkill(shanzhi)
Fk:loadTranslationTable{
    ["ysch3_bazheng"] = "霸政",
    [":ysch3_bazheng"] = "锁定技，所有角色视为拥有“权计”，且其他角色的“权”于你回合内视为“<a href='ysch3_shencaizhang'>杖</a>”，于其回合结束时视为“<a href='ysch3_shencaisi'>死</a>”。",
    ["ysch3_shencaizhang"] = "无法响应【杀】",
    ["ysch3_shencaisi"] = "回合结束时，若你“死”标记个数大于场上存活人数，你死亡。",
    ["ysch3_quanji"] = "权计",
    [":ysch3_quanji"] = "出牌阶段结束时，若你的手牌数大于你的体力值，或当你受到1点伤害后，你可以摸一张牌，然后你将一张手牌置于武将牌上，称为“权”；你的手牌上限+X（X为“权”数）。",
    ["ysch3__zhonghui_power"] = "权",
    ["#ysch3_quanji-push"] = "权计：选择1张手牌作为“权”置于武将牌上",
    ["ysch3_shanzhi"] = "擅执",
    [":ysch3_shanzhi"] = "当你使用伤害牌指定唯一目标时，可令其选择X项：1.交给你一张牌；2.此牌伤害基数+1；3.令你移动一张“权”。（X为你们武将牌上的牌数差）",
    ["#ysch3_shanzhi"] = "擅执：你可以令%dest选择%arg项并执行",
    ["#ysch3_shanzhi-choice1"] = "交给%dest一张牌",
    ["#ysch3_shanzhi-choice2"] = "此%arg伤害基数+1",
    ["#ysch3_shanzhi-choice3"] = "令%dest移动一张“权”",
    ["#ysch3_shanzhi-choice0"] = "擅执：移动一张“权”",

    ["$ysch3_bazheng1"] = "吾令既出，安敢不从？",
    ["$ysch3_bazheng2"] = "汝行此举，是要谋反吗？",
    ["$ysch3_shanzhi1"] = "无我手令，汝意欲何为？",
    ["$ysch3_shanzhi2"] = "朝中文书，需先经于我手。",
    ["~ysch3__sunjun"] = "玄弟，接下来就交给你了…",
}
local zhonghui = General:new(extension, "ysch3__zhonghui", "zishu", 3, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__zhonghui"] = "钟会",
    ["#ysch3__zhonghui"] = "误忠良贤",
    ["designer:ysch3__zhonghui"] = "铝&Sachiko",
    ["cv:ysch3__zhonghui"] = "官方",
    ["illustrator:ysch3__zhonghui"] = "佚名",
}
Fk:addQmlMark{
    name = "dynamicSkill",
    qml_path = function(name, value, p)
      return "packages/ysch_Al/qml/DynamicSkillBox"
    end,
    how_to_show = function(name, value, p)
      if type(value) == "table" then
        return tostring(#value)
      end
      return " "
    end,
}
local linzhi = fk.CreateTriggerSkill{
    name = "ysch3_linzhi",
    mute = true,
    events = {fk.TurnEnd},
    dynamic_desc = function(self, player)
        local str = "手牌数或体力值最大的角色"
        if type(player:getMark(self.name)) == "table" then
            if table.contains(player:getMark(self.name),"1") then
                str = "你"
            end
            str = str.."的回合结束时，"
            if table.contains(player:getMark(self.name),"2") then
                str = str.."你"
            else
                str = str.."当前回合角色"
            end
            str = str.."可与"
            if table.contains(player:getMark(self.name),"3") then
                str = str.."你"
            else
                str = str.."一名其他角色"
            end
            return str.."各摸一张牌，若均满足，你可将武将牌上的一个“角色”及其限定词改为“你”。"
        end
        return ""
    end,
    can_trigger = function (self, event, target, player, data)
        if type(player:getMark(self.name)) == "table" and table.contains(player:getMark(self.name),"1") then
            return target == player and player:hasSkill(self.name)
        else
            local room = player.room
            return (table.every(room:getOtherPlayers(target, false), function(p)
                return target:getHandcardNum() >= p:getHandcardNum() end) or table.every(room:getOtherPlayers(target, false), function(p)
                    return target.hp >= p.hp end)) and player:hasSkill(self.name)
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local bool = false
        local prompt = "#ysch3_linzhi_use1"
        local cp = table.find(player.room.alive_players, function(p) return p.phase ~= Player.NotActive end)
        if cp ~= nil and table.every(room:getOtherPlayers(cp, false), function(p)
            return cp:getHandcardNum() >= p:getHandcardNum() end) and table.every(room:getOtherPlayers(cp, false), function(p)
                return cp.hp >= p.hp end) then
            bool = true
        end
        if type(player:getMark(self.name)) == "table" and table.contains(player:getMark(self.name),"1") then
            bool = true
        end
        if type(player:getMark(self.name)) == "table" and table.contains(player:getMark(self.name),"2") then
            cp = player
        end
        if cp == nil or cp.dead then return end
        local targets = room:getOtherPlayers(cp, false)
        if type(player:getMark(self.name)) == "table" and table.contains(player:getMark(self.name),"3") then
            prompt = "#ysch3_linzhi_use2::"..player.id
            targets = {player}
        end
        local result = room:askForChoosePlayers(cp,table.map(targets,Util.IdMapper),1,1,prompt,self.name)
        if #result > 0 then
            room:notifySkillInvoked(player,self.name,"offensive")
            local drawP = room:getPlayerById(result[1])
            cp:drawCards(1,self.name)
            drawP:drawCards(1,self.name)
            if bool then
                local skills, all_skills = {}, {"ysch3_linzhi","ysch3_jili","ysch3_yuding"}
                for _, v in ipairs(all_skills) do
                    if player:hasSkill(v) and (player:getMark(v) == 0 or #player:getMark(v) < 3) then
                        table.insert(skills,v)
                    end
                end
                if #skills > 0 then
                    table.insert(skills,"Cancel")
                    local skill,correct = nil,nil
                    while skill == nil or (skill ~= "Cancel" and correct == "Back") do
                        skill = room:askForChoice(player,skills,self.name,"#ysch3_linzhi-choose",true)
                        if skill ~= nil and skill ~= "Cancel" then
                            local choices, all_choices= {}, {"#"..skill.."-choice1","#"..skill.."-choice2","#"..skill.."-choice3","Back"}
                            for i, v in ipairs(all_choices) do
                                if type(player:getMark(skill)) ~= "table" or not table.contains(player:getMark(skill),tostring(i)) then
                                    table.insert(choices,v)
                                end
                            end
                            correct = room:askForChoice(player,choices,self.name,"#ysch3_linzhi-correct",false,all_choices)
                            if correct ~= nil and correct ~= "Back" then
                                local x = correct:sub(#correct)
                                local arr = type(player:getMark(skill)) == "table" and player:getMark(skill) or {}
                                local dynamic = {}
                                table.insert(arr,x)
                                for i, v in ipairs(all_choices) do
                                    if table.contains(arr,tostring(i)) then
                                        table.insert(dynamic,v)
                                    end
                                end
                                room:setPlayerMark(player,skill,arr)
                                room:setPlayerMark(player,"@[dynamicSkill]"..skill,dynamic)
                                p(player:getMark("@[dynamicSkill]"..skill))
                            end
                        end
                    end
                end
            end
        end
    end,
}
zhonghui:addSkill(linzhi)
local jili = fk.CreateActiveSkill{
    name = "ysch3_jili",
    dynamic_desc = function(self, player)
        local str = "手牌数最少角色"
        if type(player:getMark(self.name)) == "table" then
            if table.contains(player:getMark(self.name),"1") then
                str = "你"
            end
            str = str.."/"
            if table.contains(player:getMark(self.name),"2") then
                str = str.."你"
            else
                str = str.."体力值最低角色"
            end
            str = str.."的出牌阶段限一次，其可以令"
            if table.contains(player:getMark(self.name),"3") then
                str = str.."你"
            else
                str = str.."一名其他角色"
            end
            return str.."摸两张牌/回复1点体力。"
        end
        return ""
    end,
    attached_skill_name = "ysch3_jili&",

    target_num = 1,
    card_num = 0,
    prompt = "#ysch3_jili",
    interaction = function(self)
        local choices ,all_choices = {},{"#ysch3_jili1:::".."其他角色","#ysch3_jili2:::".."其他角色"}
        if Self:hasSkill(self.name) and type(Self:getMark(self.name)) == "table" and table.contains(Self:getMark(self.name),"3") then
            if #table.filter(Fk:currentRoom().alive_players, function(p)
                return p:hasSkill(self.name) and (type(p:getMark(self.name)) ~= "table" or not table.contains(p:getMark(self.name),"3"))
            end) > 0 then
                all_choices = {"#ysch3_jili1:::".."一名角色","#ysch3_jili2:::".."一名角色"}
            else
                all_choices = {"#ysch3_jili1:::".."你","#ysch3_jili2:::".."你"}
            end
        end
        for i, v in ipairs(all_choices) do
            if Self:getMark("ysch3_jili"..tostring(i).."-phase") < 1 then
                if i == 1 then
                    if (Self:hasSkill(self.name) and type(Self:getMark(self.name)) == "table" and table.contains(Self:getMark(self.name),"1"))
                    or table.every(Fk:currentRoom().alive_players, function(p)
                        return Self:getHandcardNum() <= p:getHandcardNum() end) then
                            table.insert(choices,v)
                    end
                else
                    if (Self:hasSkill(self.name) and type(Self:getMark(self.name)) == "table" and table.contains(Self:getMark(self.name),"2"))
                    or table.every(Fk:currentRoom().alive_players, function(p)
                        return Self.hp <= p.hp end) then
                            table.insert(choices,v)
                    end
                end
            end
        end
        return UI.ComboBox {choices = choices}
    end,
    can_use = function (self, player)
        if (player:hasSkill(self.name) and type(player:getMark(self.name)) == "table" and table.contains(player:getMark(self.name),"1"))
        or table.every(Fk:currentRoom().alive_players, function(p)
            return player:getHandcardNum() <= p:getHandcardNum() end) then
                if player:getMark("ysch3_jili1-phase") < 1 then
                    return true
                end
        end

        if (player:hasSkill(self.name) and type(player:getMark(self.name)) == "table" and table.contains(player:getMark(self.name),"2"))
        or table.every(Fk:currentRoom().alive_players, function(p)
            return player.hp <= p.hp end) then
                if player:getMark("ysch3_jili2-phase") < 1 then
                    return true
                end
        end

        return false
    end,
    card_filter = Util.FalseFunc,
    target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
        local tp = Fk:currentRoom():getPlayerById(to_select)
        if string.sub(self.interaction.data,12,12) == "2" and not tp:isWounded() then
            return false
        end

        if Self:hasSkill(self.name) and type(Self:getMark(self.name)) == "table" and table.contains(Self:getMark(self.name),"3") then
            if #table.filter(Fk:currentRoom().alive_players, function(p)
                return p:hasSkill(self.name) and (type(p:getMark(self.name)) ~= "table" or not table.contains(p:getMark(self.name),"3"))
            end) > 0 then
                return true
            else
                return to_select == player.id
            end
        else
            return to_select ~= player.id
        end
    end,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        local choice = self.interaction.data
        local to = room:getPlayerById(effect.tos[1])
        local x = string.sub(choice,12,12)
        room:addPlayerMark(player,"ysch3_jili"..x.."-phase")
        if x == "1" then
            to:drawCards(2,self.name)
        elseif to:isWounded() then
            room:recover({
                who = to,
                num = 1,
                recoverBy = player,
                skillName = self.name,
            })
        end
    end,
}
zhonghui:addSkill(jili)
local jili_true = fk.CreateActiveSkill{
    name = "ysch3_jili&",
    dynamic_desc = function(self, player)
        local str ,bool = "", false
        if #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_jili") and type(p:getMark("ysch3_jili")) == "table" and table.contains(p:getMark("ysch3_jili"),"1")
        end) == 0  or #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_jili") and (type(p:getMark("ysch3_jili")) ~= "table" or not table.contains(p:getMark("ysch3_jili"),"1"))
        end) > 0 then
            if table.every(Fk:currentRoom().alive_players, function(p)
                return player:getHandcardNum() <= p:getHandcardNum() end) then
                    bool = true
                    str = str.."出牌阶段限一次，你可以令"
                    if #table.filter(Fk:currentRoom().alive_players, function(p)
                        return p:hasSkill("ysch3_jili") and type(p:getMark("ysch3_jili")) == "table" and table.contains(p:getMark("ysch3_jili"),"3")
                    end) > 0 then
                        local tp = table.filter(Fk:currentRoom().alive_players, function(p)
                            return p:hasSkill("ysch3_jili") and type(p:getMark("ysch3_jili")) == "table" and table.contains(p:getMark("ysch3_jili"),"3")
                        end)[1]
                        if #table.filter(Fk:currentRoom().alive_players, function(p)
                            return p:hasSkill("ysch3_jili") and (type(p:getMark("ysch3_jili")) ~= "table" or not table.contains(p:getMark("ysch3_jili"),"3"))
                        end) == 0 then
                            str = str..Fk:translate(tp.general)
                        else
                            str = str.."一名其他角色或"..Fk:translate(tp.general)
                        end
                    else
                        str = str.."一名其他角色"
                    end
                    str = str.."摸两张牌。"
            end
        end

        if #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_jili") and type(p:getMark("ysch3_jili")) == "table" and table.contains(p:getMark("ysch3_jili"),"2")
        end) == 0  or #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_jili") and (type(p:getMark("ysch3_jili")) ~= "table" or not table.contains(p:getMark("ysch3_jili"),"2"))
        end) > 0 then
            if table.every(Fk:currentRoom().alive_players, function(p)
                return player.hp <= p.hp end) then
                    bool = true
                    str = str.."出牌阶段限一次，你可以令"
                    if #table.filter(Fk:currentRoom().alive_players, function(p)
                        return p:hasSkill("ysch3_jili") and type(p:getMark("ysch3_jili")) == "table" and table.contains(p:getMark("ysch3_jili"),"3")
                    end) > 0 then
                        local tp = table.filter(Fk:currentRoom().alive_players, function(p)
                            return p:hasSkill("ysch3_jili") and type(p:getMark("ysch3_jili")) == "table" and table.contains(p:getMark("ysch3_jili"),"3")
                        end)[1]
                        if #table.filter(Fk:currentRoom().alive_players, function(p)
                            return p:hasSkill("ysch3_jili") and (type(p:getMark("ysch3_jili")) ~= "table" or not table.contains(p:getMark("ysch3_jili"),"3"))
                        end) == 0 then
                            str = str..Fk:translate(tp.general)
                        else
                            str = str.."一名其他角色或"..Fk:translate(tp.general)
                        end
                    else
                        str = str.."一名其他角色"
                    end
                    str = str.."回复1点体力。"
            end
        end

        if bool == true then
            return str
        else
            return "未达到觊立条件"
        end
    end,
    target_num = 1,
    card_num = 0,
    prompt = "#ysch3_jili",
    interaction = function(self)
        local choices ,all_choices = {},{"#ysch3_jili1:::".."其他角色","#ysch3_jili2:::".."其他角色"}
        if #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_jili") and type(p:getMark("ysch3_jili")) == "table" and table.contains(p:getMark("ysch3_jili"),"3")
        end) > 0 then
            local tp = table.filter(Fk:currentRoom().alive_players, function(p)
                return p:hasSkill("ysch3_jili") and type(p:getMark("ysch3_jili")) == "table" and table.contains(p:getMark("ysch3_jili"),"3")
            end)[1]
            if #table.filter(Fk:currentRoom().alive_players, function(p)
                return p:hasSkill("ysch3_jili") and (type(p:getMark("ysch3_jili")) ~= "table" or not table.contains(p:getMark("ysch3_jili"),"3"))
            end) > 0 then
                all_choices = {"#ysch3_jili1:::".."其他角色或"..Fk:translate(tp.general),"#ysch3_jili2:::".."其他角色或"..Fk:translate(tp.general)}
            else
                all_choices = {"#ysch3_jili1:::"..Fk:translate(tp.general),"#ysch3_jili2:::"..Fk:translate(tp.general)}
            end
        end
        for i, v in ipairs(all_choices) do
            if Self:getMark("ysch3_jili"..tostring(i).."-phase") < 1 then
                if i == 1 then
                    if #table.filter(Fk:currentRoom().alive_players, function(p)
                        return p:hasSkill("ysch3_jili") and type(p:getMark("ysch3_jili")) == "table" and table.contains(p:getMark("ysch3_jili"),"1")
                    end) == 0  or #table.filter(Fk:currentRoom().alive_players, function(p)
                        return p:hasSkill("ysch3_jili") and (type(p:getMark("ysch3_jili")) ~= "table" or not table.contains(p:getMark("ysch3_jili"),"1"))
                    end) > 0 then
                        if table.every(Fk:currentRoom().alive_players, function(p)
                            return Self:getHandcardNum() <= p:getHandcardNum() end) then
                            table.insert(choices,v)
                        end
                    end
                else
                    if #table.filter(Fk:currentRoom().alive_players, function(p)
                        return p:hasSkill("ysch3_jili") and type(p:getMark("ysch3_jili")) == "table" and table.contains(p:getMark("ysch3_jili"),"2")
                    end) == 0  or #table.filter(Fk:currentRoom().alive_players, function(p)
                        return p:hasSkill("ysch3_jili") and (type(p:getMark("ysch3_jili")) ~= "table" or not table.contains(p:getMark("ysch3_jili"),"2"))
                    end) > 0 then
                        if table.every(Fk:currentRoom().alive_players, function(p)
                            return Self.hp <= p.hp end) then
                            table.insert(choices,v)
                        end
                    end
                end
            end
        end
        return UI.ComboBox {choices = choices}
    end,
    can_use = function (self, player)
        if #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_jili") and type(p:getMark("ysch3_jili")) == "table" and table.contains(p:getMark("ysch3_jili"),"1")
        end) == 0  or #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_jili") and (type(p:getMark("ysch3_jili")) ~= "table" or not table.contains(p:getMark("ysch3_jili"),"1"))
        end) > 0 then
            if table.every(Fk:currentRoom().alive_players, function(p)
                return player:getHandcardNum() <= p:getHandcardNum() end) and player:getMark("ysch3_jili1-phase") < 1 then
                return true
            end
        end

        if #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_jili") and type(p:getMark("ysch3_jili")) == "table" and table.contains(p:getMark("ysch3_jili"),"2")
        end) == 0  or #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_jili") and (type(p:getMark("ysch3_jili")) ~= "table" or not table.contains(p:getMark("ysch3_jili"),"2"))
        end) > 0 then
            if table.every(Fk:currentRoom().alive_players, function(p)
                return player.hp <= p.hp end) and player:getMark("ysch3_jili2-phase") < 1 then
                return true
            end
        end

        return false
    end,
    card_filter = Util.FalseFunc,
    target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
        local tp = Fk:currentRoom():getPlayerById(to_select)
        if string.sub(self.interaction.data,12,12) == "2" and not tp:isWounded() then
            return false
        end
        if #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_jili") and type(p:getMark("ysch3_jili")) == "table" and table.contains(p:getMark("ysch3_jili"),"3")
        end) > 0 then
            if #table.filter(Fk:currentRoom().alive_players, function(p)
                return p:hasSkill("ysch3_jili") and (type(p:getMark("ysch3_jili")) ~= "table" or not table.contains(p:getMark("ysch3_jili"),"3"))
            end) > 0 then
                return (tp:hasSkill("ysch3_jili")  and type(tp:getMark("ysch3_jili")) == "table" and table.contains(tp:getMark("ysch3_jili"),"3")) or to_select ~= player.id
            else
                return (tp:hasSkill("ysch3_jili")  and type(tp:getMark("ysch3_jili")) == "table" and table.contains(tp:getMark("ysch3_jili"),"3"))
            end
        else
            return to_select ~= player.id
        end
    end,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        local choice = self.interaction.data
        local to = room:getPlayerById(effect.tos[1])
        local x = string.sub(choice,12,12)
        room:addPlayerMark(player,"ysch3_jili"..x.."-phase")
        player:broadcastSkillInvoke("ysch3_jili")
        if x == "1" then
            to:drawCards(2,"ysch3_jili")
        elseif to:isWounded() then
            room:recover({
                who = to,
                num = 1,
                recoverBy = player,
                skillName = "ysch3_jili",
            })
        end
    end,
}
Fk:addSkill(jili_true)
local yuding = fk.CreateActiveSkill{
    name = "ysch3_yuding",
    dynamic_desc = function(self, player)
        local str = "体力值最多角色"
        if type(player:getMark(self.name)) == "table" then
            if table.contains(player:getMark(self.name),"1") then
                str = "你"
            end
            str = str.."/"
            if table.contains(player:getMark(self.name),"2") then
                str = str.."你"
            else
                str = str.."手牌数最多角色"
            end
            str = str.."的出牌阶段限一次，其可以分配1点伤害/弃置"
            if table.contains(player:getMark(self.name),"3") then
                str = str.."你"
            else
                str = str.."一至两名角色"
            end
            return str.."区域内至多两张牌。"
        end
        return ""
    end,
    attached_skill_name = "ysch3_yuding&",

    max_target_num = 2,
    min_target_num = 1,
    card_num = 0,
    prompt = "#ysch3_yuding",
    interaction = function(self)
        local choices ,all_choices = {},{"#ysch3_yuding1","#ysch3_yuding2:::".."一至两名角色"}
        if Self:hasSkill(self.name) and type(Self:getMark(self.name)) == "table" and table.contains(Self:getMark(self.name),"3") then
            if #table.filter(Fk:currentRoom().alive_players, function(p)
                return p:hasSkill(self.name) and (type(p:getMark("ysch3_jili")) ~= "table" or not table.contains(p:getMark(self.name),"3"))
            end) == 0 then
                all_choices = {"#ysch3_yuding1","#ysch3_yuding2:::".."你"}
            end
        end

        for i, v in ipairs(all_choices) do
            if Self:getMark("ysch3_yuding"..tostring(i).."-phase") < 1 then
                if i == 1 then
                    if (Self:hasSkill(self.name) and type(Self:getMark(self.name)) == "table" and table.contains(Self:getMark(self.name),"1"))
                    or table.every(Fk:currentRoom().alive_players, function(p)
                        return Self.hp >= p.hp end) then
                            table.insert(choices,v)
                    end
                else
                    if (Self:hasSkill(self.name) and type(Self:getMark(self.name)) == "table" and table.contains(Self:getMark(self.name),"2"))
                    or table.every(Fk:currentRoom().alive_players, function(p)
                        return Self:getHandcardNum() >= p:getHandcardNum() end) then
                            table.insert(choices,v)
                    end
                end
            end
        end
        return UI.ComboBox {choices = choices}
    end,
    can_use = function (self, player)
        if (player:hasSkill(self.name) and type(player:getMark(self.name)) == "table" and table.contains(player:getMark(self.name),"1"))
        or table.every(Fk:currentRoom().alive_players, function(p)
            return player.hp >= p.hp end) then
                if player:getMark("ysch3_yuding1-phase") < 1 then
                    return true
                end
        end

        if (player:hasSkill(self.name) and type(player:getMark(self.name)) == "table" and table.contains(player:getMark(self.name),"2"))
        or table.every(Fk:currentRoom().alive_players, function(p)
            return player:getHandcardNum() >= p:getHandcardNum() end) then
                if player:getMark("ysch3_yuding2-phase") < 1 then
                    return true
                end
        end

        return false
    end,
    card_filter = Util.FalseFunc,
    target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
        local tp = Fk:currentRoom():getPlayerById(to_select)
        if string.sub(self.interaction.data,14,14) == "1" then
            return #selected == 0
        else
            if player:hasSkill(self.name) and type(player:getMark(self.name)) == "table" and table.contains(player:getMark(self.name),"3") and #table.filter(Fk:currentRoom().alive_players, function(p)
                return p:hasSkill("ysch3_yuding") and (type(p:getMark("ysch3_yuding")) ~= "table" or not table.contains(p:getMark("ysch3_yuding"),"3"))
            end) == 0 then
                return to_select == player.id and not tp:isAllNude()
            else
                return not tp:isAllNude()
            end
        end
    end,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        local choice = self.interaction.data
        local to1 = room:getPlayerById(effect.tos[1])
        local x = string.sub(choice,14,14)
        room:addPlayerMark(player,"ysch3_yuding"..x.."-phase")
        if x == "1" then
            room:damage({
                from = player,
                to = to1,
                damage = 1,
                skillName = self.name,
            })
        else if #effect.tos > 1 then
                local to2 = room:getPlayerById(effect.tos[2])
                local cid1 = room:askForCardChosen(player, to1, "hej", self.name, "#ysch3_yuding-discard1::"..to1.id)
                room:throwCard({cid1}, self.name, to1, player)
                local cid2 = room:askForCardChosen(player, to2, "hej", self.name, "#ysch3_yuding-discard1::"..to2.id)
                room:throwCard({cid2}, self.name, to2, player)
            else
                local cid = room:askForCardsChosen(player, to1, 1, 2, "hej", self.name, "#ysch3_yuding-discard2::"..to1.id)
                room:throwCard(cid, self.name, to1, player)
            end
        end
    end,
}
local yuding_true = fk.CreateActiveSkill{
    name = "ysch3_yuding&",
    dynamic_desc = function(self, player)
        local str ,bool = "", false
        if #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_yuding") and type(p:getMark("ysch3_yuding")) == "table" and table.contains(p:getMark("ysch3_yuding"),"1")
        end) == 0  or #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_yuding") and (type(p:getMark("ysch3_yuding")) ~= "table" or not table.contains(p:getMark("ysch3_yuding"),"1"))
        end) > 0 then
            if table.every(Fk:currentRoom().alive_players, function(p)
                return player.hp >= p.hp end) then
                    bool = true
                    str = str.."出牌阶段限一次，你可以分配1点伤害。"
            end
        end

        if #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_yuding") and type(p:getMark("ysch3_yuding")) == "table" and table.contains(p:getMark("ysch3_yuding"),"2")
        end) == 0  or #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_yuding") and (type(p:getMark("ysch3_yuding")) ~= "table" or not table.contains(p:getMark("ysch3_yuding"),"2"))
        end) > 0 then
            if table.every(Fk:currentRoom().alive_players, function(p)
                return player:getHandcardNum() >= p:getHandcardNum() end) then
                    bool = true
                    str = str.."出牌阶段限一次，你可以弃置"
                    if #table.filter(Fk:currentRoom().alive_players, function(p)
                        return p:hasSkill("ysch3_yuding") and type(p:getMark("ysch3_yuding")) == "table" and table.contains(p:getMark("ysch3_yuding"),"3")
                    end) > 0 and #table.filter(Fk:currentRoom().alive_players, function(p)
                        return p:hasSkill("ysch3_yuding") and (type(p:getMark("ysch3_yuding")) ~= "table" or not table.contains(p:getMark("ysch3_yuding"),"3"))
                    end) == 0 then
                        local tp = table.filter(Fk:currentRoom().alive_players, function(p)
                            return p:hasSkill("ysch3_yuding") and type(p:getMark("ysch3_yuding")) == "table" and table.contains(p:getMark("ysch3_yuding"),"3")
                        end)[1]
                        str = str..Fk:translate(tp.general)
                    else
                        str = str.."一至两名角色"
                    end
                    str = str.."区域内至多两张牌。"
            end
        end

        if bool == true then
            return str
        else
            return "未达到觎鼎条件"
        end
    end,
    max_target_num = 2,
    min_target_num = 1,
    card_num = 0,
    prompt = "#ysch3_yuding",
    interaction = function(self)
        local choices ,all_choices = {},{"#ysch3_yuding1","#ysch3_yuding2:::".."一至两名角色"}
        if #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_yuding") and type(p:getMark("ysch3_yuding")) == "table" and table.contains(p:getMark("ysch3_yuding"),"3")
        end) > 0 then
            local tp = table.filter(Fk:currentRoom().alive_players, function(p)
                return p:hasSkill("ysch3_yuding") and type(p:getMark("ysch3_yuding")) == "table" and table.contains(p:getMark("ysch3_yuding"),"3")
            end)[1]
            if #table.filter(Fk:currentRoom().alive_players, function(p)
                return p:hasSkill("ysch3_yuding") and (type(p:getMark("ysch3_yuding")) ~= "table" or not table.contains(p:getMark("ysch3_yuding"),"3"))
            end) == 0 then
                all_choices = {"#ysch3_yuding1","#ysch3_yuding2:::"..Fk:translate(tp.general)}
            end
        end
        for i, v in ipairs(all_choices) do
            if Self:getMark("ysch3_yuding"..tostring(i).."-phase") < 1 then
                if i == 1 then
                    if #table.filter(Fk:currentRoom().alive_players, function(p)
                        return p:hasSkill("ysch3_yuding") and type(p:getMark("ysch3_yuding")) == "table" and table.contains(p:getMark("ysch3_yuding"),"1")
                    end) == 0  or #table.filter(Fk:currentRoom().alive_players, function(p)
                        return p:hasSkill("ysch3_yuding") and (type(p:getMark("ysch3_yuding")) ~= "table" or not table.contains(p:getMark("ysch3_yuding"),"1"))
                    end) > 0 then
                        if table.every(Fk:currentRoom().alive_players, function(p)
                            return Self.hp >= p.hp end) then
                            table.insert(choices,v)
                        end
                    end
                else
                    if #table.filter(Fk:currentRoom().alive_players, function(p)
                        return p:hasSkill("ysch3_yuding") and type(p:getMark("ysch3_yuding")) == "table" and table.contains(p:getMark("ysch3_yuding"),"2")
                    end) == 0  or #table.filter(Fk:currentRoom().alive_players, function(p)
                        return p:hasSkill("ysch3_yuding") and (type(p:getMark("ysch3_yuding")) ~= "table" or not table.contains(p:getMark("ysch3_yuding"),"2"))
                    end) > 0 then
                        if table.every(Fk:currentRoom().alive_players, function(p)
                            return Self:getHandcardNum() >= p:getHandcardNum() end) then
                            table.insert(choices,v)
                        end
                    end
                end
            end
        end
        return UI.ComboBox {choices = choices}
    end,
    can_use = function (self, player)
        if #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_yuding") and type(p:getMark("ysch3_yuding")) == "table" and table.contains(p:getMark("ysch3_yuding"),"1")
        end) == 0  or #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_yuding") and (type(p:getMark("ysch3_yuding")) ~= "table" or not table.contains(p:getMark("ysch3_yuding"),"1"))
        end) > 0 then
            if table.every(Fk:currentRoom().alive_players, function(p)
                return player.hp >= p.hp end) and player:getMark("ysch3_yuding1-phase") < 1 then
                return true
            end
        end

        if #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_yuding") and type(p:getMark("ysch3_yuding")) == "table" and table.contains(p:getMark("ysch3_yuding"),"2")
        end) == 0  or #table.filter(Fk:currentRoom().alive_players, function(p)
            return p:hasSkill("ysch3_yuding") and (type(p:getMark("ysch3_yuding")) ~= "table" or not table.contains(p:getMark("ysch3_yuding"),"2"))
        end) > 0 then
            if table.every(Fk:currentRoom().alive_players, function(p)
                return player:getHandcardNum() >= p:getHandcardNum() end) and player:getMark("ysch3_yuding2-phase") < 1 then
                return true
            end
        end

        return false
    end,
    card_filter = Util.FalseFunc,
    target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
        local tp = Fk:currentRoom():getPlayerById(to_select)
        if string.sub(self.interaction.data,14,14) == "1" then
            return #selected == 0
        else
            if #table.filter(Fk:currentRoom().alive_players, function(p)
                return p:hasSkill("ysch3_yuding") and type(p:getMark("ysch3_yuding")) == "table" and table.contains(p:getMark("ysch3_yuding"),"3")
            end) > 0 and #table.filter(Fk:currentRoom().alive_players, function(p)
                return p:hasSkill("ysch3_yuding") and (type(p:getMark("ysch3_yuding")) ~= "table" or not table.contains(p:getMark("ysch3_yuding"),"3"))
            end) == 0 then
                return tp:hasSkill("ysch3_yuding") and type(tp:getMark("ysch3_yuding")) == "table" and table.contains(tp:getMark("ysch3_yuding"),"3") and not tp:isAllNude()
            else
                return not tp:isAllNude()
            end
        end
    end,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        local choice = self.interaction.data
        local to1 = room:getPlayerById(effect.tos[1])
        local x = string.sub(choice,14,14)
        room:addPlayerMark(player,"ysch3_yuding"..x.."-phase")
        player:broadcastSkillInvoke("ysch3_yuding")
        if x == "1" then
            room:damage({
                from = player,
                to = to1,
                damage = 1,
                skillName = self.name,
            })
        else if #effect.tos > 1 then
                local to2 = room:getPlayerById(effect.tos[2])
                local cid1 = room:askForCardChosen(player, to1, "hej", self.name, "#ysch3_yuding-discard1::"..to1.id)
                room:throwCard({cid1}, self.name, to1, player)
                local cid2 = room:askForCardChosen(player, to2, "hej", self.name, "#ysch3_yuding-discard1::"..to2.id)
                room:throwCard({cid2}, self.name, to2, player)
            else
                local cid = room:askForCardsChosen(player, to1, 1, 2, "hej", self.name, "#ysch3_yuding-discard2::"..to1.id)
                room:throwCard(cid, self.name, to1, player)
            end
        end
    end,
}
Fk:addSkill(yuding_true)
zhonghui:addSkill(yuding)
Fk:loadTranslationTable{
    ["ysch3_linzhi"] = "鳞志",
    [":ysch3_linzhi"] = "手牌数或体力值最大的角色回合结束时，当前回合角色可与一名其他角色各摸一张牌，若均满足，你可将武将牌上的一个“角色”及其限定词改为“你”。",
    ["@[dynamicSkill]ysch3_linzhi"] = "鳞志",
    ["#ysch3_linzhi-choice1"] = "手牌数或体力值最大的角色",
    ["#ysch3_linzhi-choice2"] = "当前回合角色",
    ["#ysch3_linzhi-choice3"] = "一名其他角色",
    ["#ysch3_jili-choice1"] = "手牌数最少角色",
    ["#ysch3_jili-choice2"] = "体力值最低角色",
    ["#ysch3_jili-choice3"] = "一名其他角色",
    ["#ysch3_yuding-choice1"] = "体力值最多角色",
    ["#ysch3_yuding-choice2"] = "手牌数最多角色",
    ["#ysch3_yuding-choice3"] = "一至两名角色",
    ["Back"] = "返回",
    ["#ysch3_linzhi_use1"] = "鳞志：你可以与一名其他角色各摸一张牌",
    ["#ysch3_linzhi_use2"] = "鳞志：你可以与%dest各摸一张牌",
    ["#ysch3_linzhi-choose"] = "鳞志：你可以修改武将牌上的一个技能",
    ["#ysch3_linzhi-correct"] = "鳞志：你可以将技能描述中的一个“角色”及其限定词改为“你”",
    ["ysch3_jili"] = "觊立",
    ["ysch3_jili&"] = "觊立",
    [":ysch3_jili&"] = "手牌数最少角色的出牌阶段各限一次，其可令一名其他角色摸两张牌。<br>体力值最低角色的出牌阶段限一次，其可令一名其他角色回复1点体力。",
    [":ysch3_jili"] = "手牌数最少角色/体力值最低角色的出牌阶段限一次，其可以令一名其他角色摸两张牌/回复1点体力。",
    ["@[dynamicSkill]ysch3_jili"] = "觊立",
    ["#ysch3_jili"] = "觊立：请选择",
    ["#ysch3_jili1"] = "令%arg摸两张牌",
    ["#ysch3_jili2"] = "令%arg回复1点体力",
    ["ysch3_yuding"] = "觎鼎",
    ["ysch3_yuding&"] = "觎鼎",
    [":ysch3_yuding&"] = "体力值最多角色的出牌阶段限一次，其可以分配1点伤害。<br>手牌数最多角色的出牌阶段限一次，其可以弃置一至两名角色区域内至多两张牌。",
    [":ysch3_yuding"] = "体力值最多角色/手牌数最多角色的出牌阶段限一次，其可以分配1点伤害/弃置一至两名角色区域内至多两张牌。",
    ["@[dynamicSkill]ysch3_yuding"] = "觎鼎",
    ["#ysch3_yuding"] = "觎鼎：请选择",
    ["#ysch3_yuding1"] = "分配1点伤害",
    ["#ysch3_yuding2"] = "弃置%arg区域内至多两张牌",
    ["#ysch3_yuding-discard1"] = "觎鼎：弃置%dest区域内一张牌",
    ["#ysch3_yuding-discard2"] = "觎鼎：弃置%dest区域内至多两张牌",

    ["$ysch3_linzhi1"] = "不为刀下脍，且做俎上刀。",
    ["$ysch3_linzhi2"] = "蛇可吞象，我钟会亦可吞天食地！",
    ["$ysch3_jili1"] = "大争之世，英雄弄风云，吾辈空叹否？",
    ["$ysch3_jili2"] = "历经风浪至此，会不可止步于龙门。",
    ["$ysch3_yuding1"] = "我欲问鼎天下，试问谁与争锋？",
    ["$ysch3_yuding2"] = "今长缨在手，欲问鼎九州。",
    ["~ysch3__zhonghui"] = "这就是……自食恶果的下场吗？",
}

local wutugu = General:new(extension, "ysch3__wutugu", "qun", 99, 99, General.Male)--
wutugu.total_hidden = true
Fk:loadTranslationTable{
    ["ysch3__wutugu"] = "兀突骨",
    ["#ysch3__wutugu"] = "霸者重装",
    ["designer:ysch3__wutugu"] = "铝",
    ["cv:ysch3__wutugu"] = "官方",
    ["illustrator:ysch3__wutugu"] = "凡果",
}
local qiangqiang = fk.CreateTriggerSkill{
    name = "ysch3_qiangqiang",
    anim_type = "drawcard",
    frequency = Skill.Compulsory,
    events ={fk.TargetSpecified, fk.TargetConfirmed},
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and 
          (data.card.type == Card.TypeBasic or (data.card.is_damage_card and not table.contains({"fire__slash", "fire_attack", "burning_camps"}, data.card.name))) and
          (event == fk.TargetConfirmed or data.firstTarget) and not data.ysch3_qiangqiang and player:usedSkillTimes(self.name,Player.HistoryRound) < 3
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        player:drawCards(1, self.name)
        data.ysch3_qiangqiang = true
        room:addPlayerMark(player,"@ysch3_dengdeng")
        room:addPlayerMark(player,"@!ysch3_dengdeng")
        if data.card.type == Card.TypeBasic and (data.card.is_damage_card and not table.contains({"fire__slash", "fire_attack", "burning_camps"}, data.card.name)) then
            room:addPlayerMark(player,"@ysch3_dengdeng")
            room:addPlayerMark(player,"@!ysch3_dengdeng")
            data.additionalDamage = (data.additionalDamage or 0) + 1
        end
    end,
}
wutugu:addSkill(qiangqiang)
local dengdeng = fk.CreateTriggerSkill{
    name = "ysch3_dengdeng",
    anim_type = "negative",
    frequency = Skill.Compulsory,
    events = {fk.Damaged,fk.EventPhaseEnd},
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and
        (event == fk.Damaged or (player.phase == Player.Finish and player:getMark("@!ysch3_dengdeng") > 0))
    end,
    --[[on_trigger = function(self, event, target, player, data)
        local x = (event == fk.Damaged) and data.damage or 1
        for i = 1, x do
          if not player:hasSkill(self) then break end
          self:doCost(event, target, player, data)
        end
    end,]]--
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if event == fk.Damaged then
            room:addPlayerMark(player,"@ysch3_dengdeng",data.damage)
            room:addPlayerMark(player,"@!ysch3_dengdeng",data.damage)
            if data.damageType == fk.FireDamage then
                room:addPlayerMark(player,"@ysch3_dengdeng",player:getMark("@ysch3_dengdeng"))
                room:addPlayerMark(player,"@!ysch3_dengdeng",player:getMark("@!ysch3_dengdeng"))
            end
        else
            room:damage({
                to = player,
                damage = player:getMark("@!ysch3_dengdeng"),
                skillName = self.name,
            })
        end
    end,
}
wutugu:addSkill(dengdeng)
Fk:loadTranslationTable{
    ["ysch3_qiangqiang"] = "锵锵",
    [":ysch3_qiangqiang"] = "锁定技，你指定或成为基本牌或非火焰伤害牌的目标后摸一张牌，每满足一项，你获得一枚“危”，若均满足，此牌伤害基数+1。（每轮限三次）",
    ["ysch3_dengdeng"] = "噔噔",
    [":ysch3_dengdeng"] = "锁定技，当你受到伤害后，你获得等同伤害值枚“危”，若为火属性伤害，翻倍“危”。结束阶段，你受到“危”个数点无来源的伤害。",
    ["@ysch3_dengdeng"] = "危",
    ["@!ysch3_dengdeng"] = "危",

    ["$ysch3_dengdeng1"] = "你会后悔的！啊！！",
    ["$ysch3_dengdeng2"] = "这是要赶尽杀绝吗？",
    ["$ysch3_qiangqiang1"] = "找死！",
    ["$ysch3_qiangqiang2"] = "这就让你们见识见识，哈哈哈哈哈哈哈。",
}

local tongyuan = General:new(extension, "ysch3__tongyuan", "qun", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__tongyuan"] = "童渊",
    ["#ysch3__tongyuan"] = "蓬莱枪神散人",
    ["designer:ysch3__tongyuan"] = "铝",
    ["cv:ysch3__tongyuan"] = "官方",
    ["illustrator:ysch3__tongyuan"] = "M云涯",
}
local chaofeng = fk.CreateViewAsSkill{
    name = "ysch3_chaofeng",
    pattern = "slash,jink",
    dynamic_desc = function(self, player)
        if player:getMark("ysch3_shoutu") ~= 0 then
            local str = ""
            if player:getMark("@ysch3_shoutu-study") ~= 0 then
               str = "每回合限一次，" 
            end
            if table.contains(player:getMark("ysch3_shoutu"),1) then
                str = str.."你可以将一张牌当【杀】或【闪】使用或打出。"
            end
            if table.contains(player:getMark("ysch3_shoutu"),2) then
                str = str.."你使用【杀】指定目标后，可令其弃置装备区一张牌。"
            end
            if table.contains(player:getMark("ysch3_shoutu"),3) then
                str = str.."你使用或受到【杀】造成伤害时，可以重铸一张牌。"
            end
            return str
        end
    end,
    interaction = function()
        local names = {}
        if Fk.currentResponsePattern == nil and Self:canUse(Fk:cloneCard("slash")) then
          table.insertIfNeed(names, "slash")
        else
          for _, name in ipairs({"slash", "jink"}) do
            if Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(Fk:cloneCard(name)) then
              table.insertIfNeed(names, name)
            end
          end
        end
        if #names == 0 then return end
        return U.CardNameBox {choices = names}
    end,
    card_filter = function(self, to_select, selected)
        return #selected == 0
    end,
    view_as = function(self, cards)
        if #cards ~= 1 or self.interaction.data == nil then return end
        local card = Fk:cloneCard(self.interaction.data)
        card.skillName = self.name
        card:addSubcard(cards[1])
        return card
    end,
    enabled_at_play = function(self, player)
        if player:getMark("ysch3_shoutu") ~= 0 then
            if table.contains(player:getMark("ysch3_shoutu"),1) then
                if player:getMark("@ysch3_shoutu-study") ~= 0 then
                    return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
                else
                    return true
                end
            else
                return false
            end
        else
            return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
        end
    end,
    enabled_at_response = function(self, player)
        if player:getMark("ysch3_shoutu") ~= 0 then
            if table.contains(player:getMark("ysch3_shoutu"),1) then
                if player:getMark("@ysch3_shoutu-study") ~= 0 then
                    return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
                else
                    return true
                end
            else
                return false
            end
        else
            return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and player:usedSkillTimes("#ysch3_chaofeng", Player.HistoryTurn) == 0
        end
    end,
}
local chaofeng_trigger = fk.CreateTriggerSkill{
    name = "#ysch3_chaofeng",
    events = {fk.TargetSpecified,fk.DamageCaused,fk.DamageInflicted},
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill("ysch3_chaofeng") then
            if event == fk.TargetSpecified then
                if data.card.trueName == "slash" and #player.room:getPlayerById(data.to):getCardIds("e") > 0 then
                    if player:getMark("ysch3_shoutu") ~= 0 then
                        if table.contains(player:getMark("ysch3_shoutu"),2) then
                            if player:getMark("@ysch3_shoutu-study") ~= 0 then
                                return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
                            else
                                return true
                            end
                        else
                            return false
                        end
                    else
                        return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and player:usedSkillTimes("ysch3_chaofeng", Player.HistoryTurn) == 0
                    end
                end
            else
                if not player:isKongcheng() and data.card and data.card.trueName == "slash" then
                    if player:getMark("ysch3_shoutu") ~= 0 then
                        if table.contains(player:getMark("ysch3_shoutu"),3) then
                            if player:getMark("@ysch3_shoutu-study") ~= 0 then
                                return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
                            else
                                return true
                            end
                        else
                            return false
                        end
                    else
                        return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and player:usedSkillTimes("ysch3_chaofeng", Player.HistoryTurn) == 0
                    end
                end
            end
        end
    end,
    on_cost = function(self, event, target, player, data)
        if event == fk.TargetSpecified then
            return player.room:askForSkillInvoke(player, "ysch3_chaofeng", nil, "#ysch3_chaofeng2-invoke::"..data.to)
        else
            local card = player.room:askForCard(player, 1, 1, true, "ysch3_chaofeng", true, ".", "#ysch3_chaofeng3-invoke")
            if #card > 0 then
                self.cost_data = card
                return true
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if event == fk.TargetSpecified then
            local to = room:getPlayerById(data.to)
            room:askForDiscard(to, 1, 1, true, "ysch3_chaofeng", false, ".|.|.|equip", "#ysch3_chaofeng2-discard")
        else
            room:recastCard(self.cost_data, player, "ysch3_chaofeng")
        end
    end,
}
chaofeng:addRelatedSkill(chaofeng_trigger)
tongyuan:addSkill(chaofeng)
local shoutuWord = {"勤能补拙", "素材局", "叫你家家人来打", "4399停服了？", "新手教程", "下课", "EZ", "代+", "收坐骑", "自己找差距",
"投降在右上角", "师承唐启华", "未来是你们的", "暂时不考虑打职业", "统一回复没开谢谢", "征婚", "纳妾", "小段60大段150", "菜鸟驿站",
"开了吗？我说的灵智", "接原神代肝", "墨镜上车", "聘7", "元梦之星转杀"}
local shoutu = fk.CreateActiveSkill{
    name = "ysch3_shoutu",
    prompt = "#ysch3_shoutu",
    frequency = Skill.Limited,
    can_use = function(self, player)
        if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 then
            return type(player:getMark("ysch3_shoutu")) ~= "table" or #player:getMark("ysch3_shoutu") > 0
        end
    end,
    min_target_num = 1,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected, selected_cards, _, _, player)
        return to_select ~= player.id
    end,
    interaction = function(self)
        local choices, all_choices = {}, {"ysch3_chaofeng_1","ysch3_chaofeng_2","ysch3_chaofeng_3"}
        for i,v in ipairs(all_choices) do
            if type(Self:getMark("ysch3_shoutu")) ~= "table" or table.contains(Self:getMark("ysch3_shoutu"),i) then
                table.insert(choices,v)
            end
        end
        return UI.ComboBox {choices = choices, detailed = true, all_choices = all_choices}
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local to = room:getPlayerById(effect.tos[1])
        local x = tonumber(string.sub(self.interaction.data,16,16))
        local arr0 = {"壹式","貮式","叁式"}
        local arr1 = type(player:getMark("ysch3_shoutu")) == "table" and player:getMark("ysch3_shoutu") or {1,2,3}
        local arr2 = type(to:getMark("ysch3_shoutu")) == "table" and to:getMark("ysch3_shoutu") or {}
        local arr3 = {}
        table.insert(arr2,x)
        table.removeOne(arr1,x)
        for _, v in ipairs(arr2) do
            table.insert(arr3,arr0[v])
        end
        room:setPlayerMark(to,"@ysch3_chaofeng",arr3)
        room:setPlayerMark(player,"ysch3_shoutu",arr1)
        room:setPlayerMark(player,"@ysch3_shoutu-teach",Fk:translate(to.general))
        room:setPlayerMark(to,"ysch3_shoutu",arr2)
        room:setPlayerMark(to,"@ysch3_shoutu-study",Fk:translate(player.general))
        room:handleAddLoseSkills(to,"ysch3_chaofeng",self.name)
        player:chat(table.random(shoutuWord))

        p(player:usedSkillTimes(self.name, Player.HistoryGame))
    end,
}
tongyuan:addSkill(shoutu)
Fk:loadTranslationTable{
    ["ysch3_chaofeng"] = "朝凤",
    ["#ysch3_chaofeng"] = "朝凤",
    ["@ysch3_chaofeng"] = "朝凤",
    [":ysch3_chaofeng"] = "你可以将一张牌当【杀】或【闪】使用或打出。你使用【杀】指定目标后，你可令其弃置装备区一张牌。你使用或受到【杀】造成伤害时，你可以重铸一张牌。（每回合限一次）",
    [":ysch3_chaofeng_1"] = "你可以将一张牌当【杀】或【闪】使用或打出。",
    [":ysch3_chaofeng_2"] = "你使用【杀】指定目标后，可令其弃置装备区一张牌。",
    [":ysch3_chaofeng_3"] = "你使用或受到【杀】造成伤害时，可以重铸一张牌。",
    ["#ysch3_chaofeng2-invoke"] = "朝凤：你可令 %dest 弃置装备区一张牌",
    ["#ysch3_chaofeng2-discard"] = "朝凤：弃置装备区里的一张牌",
    ["#ysch3_chaofeng3-invoke"] = "朝凤：你可以重铸一张牌",
    ["ysch3_shoutu"] = "收徒",
    [":ysch3_shoutu"] = "限定技，出牌阶段，你可以删去“朝凤”中的一句和“（每回合限一次）”，将之组成新技能令一名其他角色获得之。",
    ["#ysch3_shoutu"] = "收徒：删去“朝凤”中的一句和“（每回合限一次）”，将之组成新技能令一名其他角色获得之",
    ["@ysch3_shoutu-teach"] = "收徒",
    ["@ysch3_shoutu-study"] = "被收徒",
    ["ysch3_chaofeng_1"] = "第一句",
    ["ysch3_chaofeng_2"] = "第二句",
    ["ysch3_chaofeng_3"] = "第三句",

    ["$ysch3_chaofeng1"] = "枪出惊百鸟，技现震诸雄。",
    ["$ysch3_chaofeng2"] = "出如鸾凤高翱，收若百鸟归林。",
    ["$ysch3_shoutu1"] = "此术集百家之法，当传万世。",
    ["$ysch3_shoutu2"] = "某虽无名于世，此术可传之万年。",
    ["~ysch3__tongyuan"] = "隐居山水，空老病榻。",
}

local duanwenyang = General:new(extension, "ysch3__duanwenyang", "jin", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__duanwenyang"] = "段文鸯",
    ["#ysch3__duanwenyang"] = "独骑鸱咽",
    ["designer:ysch3__duanwenyang"] = "铝",
    ["cv:ysch3__duanwenyang"] = "官方",
    ["illustrator:ysch3__duanwenyang"] = "佚名",
}
local miewu = fk.CreateViewAsSkill{
    name = "ysch3_miewu",
    anim_type = "offensive",
    pattern = ".",
    dynamic_desc = function (self, player, lang)
        local arr = type(player:getMark("ysch3_miewu")) == "table" and player:getMark("ysch3_miewu") or {"slash","duel"}
        return "你可以将【"..Util.TranslateMapper(arr[1]).."】当【"..Util.TranslateMapper(arr[2]).."】使用。"
    end,
    --[[interaction = function()
        local choices = type(Self:getMark("ysch3_miewu")) == "table" and {Self:getMark("ysch3_miewu")[2]} or {"duel"}
        return U.CardNameBox {
            choices = choices,
            all_choices = choices,
            default_choice = "AskForCardsChosen",
        }
    end,]]--
    prompt = function (self)
        local name1 = type(Self:getMark("ysch3_miewu")) == "table" and Self:getMark("ysch3_miewu")[1] or "slash"
        local name2 = type(Self:getMark("ysch3_miewu")) == "table" and Self:getMark("ysch3_miewu")[2] or "duel"
        return "#ysch3_miewu:::"..name1..":"..name2
    end,
    handly_pile = true,
    card_filter = function(self, to_select, selected)
        local name = type(Self:getMark("ysch3_miewu")) == "table" and Self:getMark("ysch3_miewu")[1] or "slash"
        return #selected == 0 and Fk:getCardById(to_select).trueName == name
    end,
    view_as = function(self, cards)
        if #cards ~= 1 then return end
        local name = type(Self:getMark("ysch3_miewu")) == "table" and Self:getMark("ysch3_miewu")[2] or "duel"
        local card = Fk:cloneCard(name)
        card.skillName = self.name
        card:addSubcard(cards[1])
        return card
    end,
    enabled_at_play = function(self, player)
        local name = type(Self:getMark("ysch3_miewu")) == "table" and Self:getMark("ysch3_miewu")[2] or "duel"
        local card = Fk:cloneCard(name)
        card.skillName = self.name
        return player:canUse(card) and not player:prohibitUse(card)
    end,
    enabled_at_response = function(self, player, response)
        if not response then
           local name = type(Self:getMark("ysch3_miewu")) == "table" and Self:getMark("ysch3_miewu")[2] or "duel"
            return Exppattern:Parse(Fk.currentResponsePattern):matchExp(".|.|.|.|"..name)
        end
    end,
    on_acquire = function (self, player, is_start)
        local room = player.room
        local arr = type(player:getMark("ysch3_miewu")) == "table" and player:getMark("ysch3_miewu") or {"slash","duel"}
        room:setPlayerMark(player,"ysch3_miewu",arr)
        room:setPlayerMark(player,"@ysch3_miewu",table.concat(table.map(arr, Util.TranslateMapper)," "))
    end,
    on_lose = function (self, player, is_death)
        player.room:setPlayerMark(player,"@ysch3_miewu",0)
    end,
}
duanwenyang:addSkill(miewu)
local kunzhan = fk.CreateTriggerSkill{
    name = "ysch3_kunzhan",
    anim_type = "switch",
    switch_skill_name = "ysch3_kunzhan",
    events = {fk.CardUsing},
    can_trigger = function(self, event, target, player, data)
        if (target == player or (data.tos and table.contains(TargetGroup:getRealTargets(data.tos), player.id))) and player:hasSkill(self) then
            return data.card.type == Card.TypeBasic or (not data.card.multiple_targets and data.card.is_damage_card)
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if player:getSwitchSkillState("ysch3_kunzhan", true) == fk.SwitchYang then
            local name = data.card.trueName
            local all_choices = type(player:getMark("ysch3_miewu")) == "table" and player:getMark("ysch3_miewu") or {"slash","duel"}
            local choices = type(player:getMark("ysch3_miewu")) == "table" and player:getMark("ysch3_miewu") or {"slash","duel"}
            if type(player:getMark("ysch3_kunzhan-after")) == "string" then
                table.removeOne(choices,player:getMark("ysch3_kunzhan-after"))
            end
            local result = room:askForChoice(player,choices,self.name,"#ysch3_kunzhan:::"..name)
            room:setPlayerMark(player,"ysch3_kunzhan-before",result)
            room:setPlayerMark(player,"ysch3_kunzhan-after",name)
            room:setPlayerMark(player,"@ysch3_kunzhan",Util.TranslateMapper(result))
            if result == all_choices[1] then
                all_choices[1] = name
            else
                all_choices[2] = name
            end
            room:setPlayerMark(player,"ysch3_miewu",all_choices)
            room:setPlayerMark(player,"@ysch3_miewu",table.concat(table.map(all_choices, Util.TranslateMapper)," "))
        else
            local name = player:getMark("ysch3_kunzhan-before")
            local cards = room:getCardsFromPileByRule(name, 1)
            if #cards == 0 then
                cards = room:getCardsFromPileByRule(name, 1, "discardPile")
            end
            if #cards > 0 then
                room:obtainCard(player, cards[1], true, fk.ReasonJustMove, nil, self.name)
            end
        end
    end,
}
duanwenyang:addSkill(kunzhan)
Fk:loadTranslationTable{
    ["ysch3_miewu"] = "滅忤",
    [":ysch3_miewu"] = "你可以将【杀】当【决斗】使用。",
    ["#ysch3_miewu"] = "滅忤：你可以将【%arg】当【%arg2】使用",
    ["@ysch3_miewu"] = "滅忤",
    ["ysch3_kunzhan"] = "困战",
    [":ysch3_kunzhan"] = "转换技，你使用/被使用基本或单体伤害牌时："..
    "①将“滅忤”中的一项改为此牌名（不能选择上次改后的牌名）；"..
    "②检索并获得上次修改掉的牌名。",
    ["#ysch3_kunzhan"] = "困战：将“滅忤”中的一项改为%arg",
    ["@ysch3_kunzhan"] = "困战",
}

local sp_caocao = General:new(extension, "ysch3__sp_caocao", "han", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__sp_caocao"] = "曹操",
    ["#ysch3__sp_caocao"] = "峥嵘而立",
    ["designer:ysch3__sp_caocao"] = "铝",
    ["cv:ysch3__sp_caocao"] = "官方",
    ["illustrator:ysch3__sp_caocao"] = "YanBai",
}
local ysch3_zhengsu_recorder = fk.CreateTriggerSkill{
    name = "ysch3_zhengsu_recorder",
  
    refresh_events = {fk.CardUsing, fk.AfterCardsMove, fk.EventPhaseEnd},
    can_refresh = function(self, event, target, player, data)
        if player.dead then return end
        local mark1, mark2, mark3 = "@zhengsu_bianzhen-turn", "@zhengsu_leijin-turn", "@zhengsu_mingzhi-turn"
        local check_play = player.phase == Player.Play and
        ((player:getMark(mark1) == "" or type(player:getMark(mark1)) == "table")
        or (player:getMark(mark2) == "" or type(player:getMark(mark2)) == "table"))
        local check_discard = player.phase == Player.Discard and
        (player:getMark(mark3) == "" or type(player:getMark(mark3)) == "table")
        if event == fk.CardUsing then
            return target == player and check_play
        elseif event == fk.AfterCardsMove then
            return check_discard
        else
            return target == player and (check_play or check_discard)
        end
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        local broadcastFailure = function (p, choice)
            room:setPlayerMark(p, "@"..choice.."-turn", "zhengsu_failure")
            for _, v in ipairs(p:getTableMark("zhengsu_skill-turn")) do
            if choice == v[3] then
                room:getPlayerById(v[1]):broadcastSkillInvoke(v[2], 3)
            end
            end
        end
        if event == fk.CardUsing then
            local mark = player:getMark("@zhengsu_leijin-turn")
            if (mark == "" or type(mark) == "table") and data.card.number > 0 then
            if mark == "" then
                mark = {}
            else
                mark = table.map(mark, function(v) return Card:strToNumber(v) end)
            end
            table.insert(mark, data.card.number)
            if #mark > 3 then table.remove(mark, 1) end
            if #mark > 1 and mark[#mark] <= mark[#mark-1] then
                broadcastFailure(player, "zhengsu_leijin")
            else
                mark = table.map(mark, function(v) return Card:getNumberStr(v) end)
                room:setPlayerMark(player, "@zhengsu_leijin-turn", mark)
            end
            end
            mark = player:getMark("@zhengsu_bianzhen-turn")
            if (mark == "" or type(mark) == "table") then
            local suit = data.card:getSuitString(true)
            if suit ~= "log_nosuit" then
                if mark == "" then mark = {} end
                if table.find(mark, function(v) return v ~= suit end) then
                broadcastFailure(player, "zhengsu_bianzhen")
                return
                elseif #mark < 2 then
                table.insert(mark, suit)
                end
                room:setPlayerMark(player, "@zhengsu_bianzhen-turn", mark)
            end
            end
        elseif event == fk.AfterCardsMove then
            local mark = player:getTableMark("@zhengsu_mingzhi-turn")
            for _, move in ipairs(data) do
            if move.from == player.id and move.skillName == "phase_discard" then
                for _, info in ipairs(move.moveInfo) do
                if info.fromArea == Card.PlayerHand then
                    local suit = Fk:getCardById(info.cardId):getSuitString(true)
                    if not table.insertIfNeed(mark, suit) then
                    broadcastFailure(player, "zhengsu_mingzhi")
                    return
                    end
                end
                end
            end
            end
            room:setPlayerMark(player, "@zhengsu_mingzhi-turn", mark)
        elseif event == fk.EventPhaseEnd then
            local mark1, mark2, mark3 = "@zhengsu_bianzhen-turn", "@zhengsu_leijin-turn", "@zhengsu_mingzhi-turn"
            if player.phase == Player.Play then
            if player:getMark(mark1) ~= 0 then
                if #player:getTableMark(mark1) >= 2 then
                room:setPlayerMark(player, mark1, "zhengsu_success")
                else
                broadcastFailure(player, "zhengsu_bianzhen")
                end
            end
            if player:getMark(mark2) ~= 0 then
                if #player:getTableMark(mark2) >= 3 then
                room:setPlayerMark(player, mark2, "zhengsu_success")
                else
                broadcastFailure(player, "zhengsu_leijin")
                end
            end
            else
            if #player:getTableMark(mark3) >= 2 then
                room:setPlayerMark(player, mark3, "zhengsu_success")
            else
                broadcastFailure(player, "zhengsu_mingzhi")
            end
            end
        end
    end,
}
Fk:addSkill(ysch3_zhengsu_recorder)
local lingfa = fk.CreateTriggerSkill{
    name = "ysch3_lingfa",
    anim_type = "support",
    mute = true,
    events = {fk.RoundStart,fk.TurnStart,fk.EventPhaseEnd,fk.RoundEnd},
    frequency = Skill.Frequent,
    can_trigger = function (self, event, target, player, data)
        if event == fk.TurnStart then
            return type(player:getMark("ysch3_lingfa_zhengsu-round")) == "table" and table.contains(player:getMark("ysch3_lingfa_zhengsu-round"),target.id)
        elseif event == fk.EventPhaseEnd then
            return player:hasSkill(self.name) and target.phase == Player.Discard and not target.dead and type(player:getMark("ysch3_lingfa_zhengsu-round")) == "table" and table.contains(player:getMark("ysch3_lingfa_zhengsu-round"),target.id)
        elseif event == fk.RoundEnd then
            return player:hasSkill(self.name) and type(player:getMark("ysch3_lingfa_zhengsu-round")) == "table"
        else
            return player:hasSkill(self.name)
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        if event == fk.RoundStart then
            local choices = {"zhengsu_leijin", "zhengsu_bianzhen", "zhengsu_mingzhi", "Cancel"}
            local choice = room:askForChoice(player, choices, self.name, "#ysch3_lingfa-choice", true)
            if choice ~= "Cancel" then
                self.cost_data = choice
                return true
            end
        else
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if event == fk.RoundStart then
            room:notifySkillInvoked(player, self.name, "support")
            player:broadcastSkillInvoke(self.name)
            local choice = self.cost_data
            local mark_name = "@" .. choice .. "-turn"
            local targets = {}
            table.insert(targets,player.id)
            local result = U.askForJointChoice(room:getOtherPlayers(player), {"#ysch3_lingfa-choice1", "#ysch3_lingfa-choice2"}, self.name, "#ysch3_lingfa-ask::"..player.id..":"..mark_name, true)
            for _, cp in ipairs(room:getOtherPlayers(player)) do
                --local cr = room:askForChoice(cp, {"#ysch3_lingfa-choice1", "#ysch3_lingfa-choice2"}, self.name, "#ysch3_lingfa-ask::"..player.id..":"..mark_name)
                local cr = result[cp.id]
                if cr == "#ysch3_lingfa-choice1" then
                    table.insert(targets,cp.id)
                else
                    room:setPlayerMark(cp,"@ysch3_lingfa-round","不从")
                end
            end
            room:setPlayerMark(player,"ysch3_lingfa_zhengsu-round",targets)
            room:setPlayerMark(player,"ysch3_lingfa_choice-round",choice)
            room.logic:addTriggerSkill(ysch3_zhengsu_recorder)
        elseif event == fk.TurnStart then
            local choice = player:getMark("ysch3_lingfa_choice-round")
            local mark_name = "@" .. choice .. "-turn"
            if target:getMark(mark_name) == 0 then
                room:setPlayerMark(target, mark_name, "")
            end
            room:addTableMark(target, "zhengsu_skill-turn", {player.id, self.name, choice})
        elseif event == fk.EventPhaseEnd then
            if U.checkZhengsu(player, target, self.name) then
                room:notifySkillInvoked(player, self.name, "drawcard")
                player:broadcastSkillInvoke(self.name,2)
                room:setPlayerMark(target,"@ysch3_lingfa-round","整肃成功")
                local choices = {"draw2"}
                if target:isWounded() then
                    table.insert(choices, 1, "recover")
                end
                local reward = room:askForChoice(target, choices, self.name, "#ysch3_lingfa-reward", false, {"draw2", "recover"})
                U.rewardZhengsu(player, target, reward, self.name)
            else
                room:notifySkillInvoked(player, self.name, "defensive")
                player:broadcastSkillInvoke(self.name,1)
                room:setPlayerMark(target,"@ysch3_lingfa-round","整肃失败")
            end
        else
            local targets = table.filter(room.alive_players, function(p) return table.contains(player:getMark("ysch3_lingfa_zhengsu-round"),p.id) and not p:isKongcheng() end)
            local discussion = U.Discussion(player, targets, self.name)
            if discussion.color == "red" then
                for _, p in ipairs(room:getAlivePlayers()) do
                    if type(p:getMark("@ysch3_lingfa-round")) == "string" and table.contains({"不从","整肃失败"},p:getMark("@ysch3_lingfa-round")) then
                        if not p.dead then room:loseHp(p, 1, self.name) end
                    end
                end
                
            elseif discussion.color == "black" then
                for _, p in ipairs(room:getAlivePlayers()) do
                    if type(p:getMark("@ysch3_lingfa-round")) == "string" and p:getMark("@ysch3_lingfa-round") == "整肃成功" then
                        if not p.dead then room:loseHp(p, 1, self.name) end
                    end
                end
            end
        end
    end,
}
sp_caocao:addSkill(lingfa)
local zhian = fk.CreateTriggerSkill{
    name = "ysch3_zhian",
    anim_type = "drawcard",
    events = {fk.AfterPhaseEnd},
    prompt = "#ysch3_zhian-choice",
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) and target.id ~= player.id and target.phase == Player.Discard and not target.dead 
        and player:usedSkillTimes(self.name, Player.HistoryRound) == 0 then
            for _, v in ipairs(target:getTableMark("zhengsu_skill-turn")) do
                return target:getMark("@" .. v[3].. "-turn") == "zhengsu_success"
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local choices = {"draw2"}
        if player:isWounded() then
            table.insert(choices, 1, "recover")
        end
        local reward = room:askForChoice(player, choices, self.name, "#ysch3_zhian-reward::"..target.id, false, {"draw2", "recover"})
        U.rewardZhengsu(player, player, reward, self.name)
    end,
}
sp_caocao:addSkill(zhian)
Fk:loadTranslationTable{
    ["ysch3_lingfa"] = "令法",
    [":ysch3_lingfa"] = "轮次开始时，你可以邀请所有角色于本轮各自回合内进行你指定的“<a href='zhengsu_desc'>整肃</a>”，当前轮次结束时你与参与者议事：<br>红色：不从或失败者失去1点体力；<br>黑色：参与且成功者失去1点体力。",
    ["@ysch3_lingfa-round"] = "令法",
    ["#ysch3_lingfa-choice"] = "是否发动 令法，邀请所有角色进行一项“整肃”",
    ["#ysch3_lingfa-choice1"] = "从",
    ["#ysch3_lingfa-choice2"] = "不从",
    ["#ysch3_lingfa-ask"] = "令法：%dest邀请你进行“%arg”整肃",
    ["#ysch3_lingfa-reward"] = "令法：“整肃”成功，选择一项整肃奖励",
    ["ysch3_zhian"] = "治暗",
    [":ysch3_zhian"] = "每轮限一次，其他角色“整肃”成功时，你也可以获得“整肃”奖励。",
    ["#ysch3_zhian-choice"] = "是否发动 治暗，也获得“整肃”奖励",
    ["#ysch3_zhian-reward"] = "治暗：%dest“整肃”成功，选择一项整肃奖励",

    ["$ysch3_lingfa1"] = "吾明令在此，汝何以犯之？",
    ["$ysch3_lingfa2"] = "法不阿贵，绳不挠曲！",
    ["$ysch3_zhian1"] = "此等蝼蚁不除，必溃千丈之堤！",
    ["$ysch3_zhian2"] = "尔等权贵贪赃枉法，岂可轻饶？！",
}

local jiangwei = General:new(extension, "ysch3__jiangwei", "zishu", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__jiangwei"] = "姜维",
    ["#ysch3__jiangwei"] = "麟耆暮耋",
    ["designer:ysch3__jiangwei"] = "铝",
    ["cv:ysch3__jiangwei"] = "佚名",
    ["illustrator:ysch3__jiangwei"] = "未知",
}
local tiaoxin = fk.CreateActiveSkill{
    name = "ysch3_tiaoxin",
    anim_type = "control",
    card_num = 0,
    target_num = 1,
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected)
        return #selected == 0 and Fk:currentRoom():getPlayerById(to_select):inMyAttackRange(Self)
    end,
    target_tip = function (self, to_select, selected, selected_cards, card, selectable, extra_data)
        if #selected > 0 and self.name == "ysch3_canfa" then
            if to_select == selected[1] then
                return "@ysch3_canfa_first"
            elseif to_select == selected[2] then
                return { {content = "@ysch3_canfa_last", type = "warning"} }
            end
        end
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local target = room:getPlayerById(effect.tos[1])
        local use = room:askForUseCard(target, "slash", "slash", "#tiaoxin-use", true, {exclusive_targets = {player.id}})
        if use then
            room:useCard(use)
        else
            if not target:isNude() then
            local card = room:askForCardChosen(player, target, "he", self.name)
            room:throwCard({card}, self.name, target, player)
            end
        end
    end
}
local kunfen = fk.CreateTriggerSkill{
    name = "ysch3_kunfen",
    anim_type = "drawcard",
    frequency = Skill.Compulsory,
    events = {fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Finish
    end,
    on_use = function(self, event, target, player, data)
        player.room:loseHp(player, 1, self.name)
        if player:isAlive() then
            player.room:drawCards(player, 2, self.name)
        end
    end,
}
Fk:addTargetTip {
    name = "ysch3_canfa_tiaoxin",
    target_tip = function (self, to_select, selected, selected_cards, card, selectable, extra_data)
        if #selected > 0 then
            if to_select == selected[1] then
                return "@ysch3_canfa_first"
            elseif to_select == selected[2] then
                return { {content = "@ysch3_canfa_last", type = "warning"} }
            end
        end
    end,
}
local canfa = fk.CreateActiveSkill{
    name = "ysch3_canfa",
    card_num = 0,
    target_num = 1,
    prompt = "#hannan",
    can_use = function(self, player)
        return not player:isKongcheng()
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected)
        return #selected == 0 and to_select ~= Self.id and Self:canPindian(Fk:currentRoom():getPlayerById(to_select))
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local target = room:getPlayerById(effect.tos[1])
        local pindian = player:pindian({target}, self.name)
        local card = nil
        if pindian.results[target.id].winner == player then
            card = pindian.fromCard
        end
        if pindian.results[target.id].winner == target then
            card = pindian.results[target.id].toCard
        end
        if card ~= nil and card.color == Card.Red then
            p(Fk.target_tips)
            p(Fk.target_tips["ysch3_tiaoxin"])
            local tos = room:askForChoosePlayers(player,table.map(player.room.alive_players, Util.IdMapper),2,2,"#ysch3_canfa_tiaoxin",self.name,true,false,"ysch3_canfa_tiaoxin")
            if #tos > 0 then
                --player:broadcastSkillInvoke("ysch3_tiaoxin")
                room:useSkill(player,tiaoxin,function ()
                    tiaoxin:onUse(player.room, {from = tos[1], tos = {tos[2]}, cards = {}})
                end,{})
            end
        else
            room:useSkill(player,kunfen,function ()
                kunfen:use(fk.SkillEffect, player, player, effect)
            end,{})
            room:endTurn()
        end
    end,
}
jiangwei:addSkill(canfa)
jiangwei:addRelatedSkill(tiaoxin)
jiangwei:addRelatedSkill(kunfen)
local wanshi = fk.CreateTriggerSkill{
    name = "ysch3_wanshi",
    mute = true,
    events = {fk.HpChanged, fk.MaxHpChanged},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and target == player and (player:getMark("ysch3_wanshi") ~= player:getLostHp())
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player,"ysch3_wanshi",player:getLostHp())
        if player:getLostHp() > 0 then
            room:notifySkillInvoked(player,self.name,"masochism")
            player:broadcastSkillInvoke(self.name)
            if not player:hasSkill("ysch3_wanlan") then
                room:handleAddLoseSkills(player,"ysch3_wanlan",self.name,true)
            end
        else
            room:handleAddLoseSkills(player,"-ysch3_wanlan",self.name,true)
        end
    end,
}
jiangwei:addSkill(wanshi)
local wanlan = fk.CreateTriggerSkill{
    name = "ysch3_wanlan",
    dynamic_desc = function (self, player, lang)
        local str = ""
        if player:getMark("ysch3_wanshi") ~= 0 then
            if player:getLostHp() < 4 then
                str  = str.."限定技，"
            end
            str  = str.."当一名角色进入濒死状态时，你可以发动此技能"
            if player:getLostHp() < 3 then
                str = str.."："
            end
            if player:getLostHp() < 2 then
                str  = str.."弃置所有手牌，"
            end
            if player:getLostHp() < 3 then
                str  = str.."令其回复体力至1点"
            end
            if player:getLostHp() < 1 then
                str  = str.."，然后你对当前回合角色造成1点伤害"
            end
            str = str.."。"
        end
        return str
    end,
    anim_type = "support",
    frequency = Skill.Limited,
    events = {fk.EnterDying},
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and (player:usedSkillTimes(self.name, Player.HistoryGame) == 0 or player:getLostHp() > 3)
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local n = player:getLostHp()
        if n < 2 or player:getMark("ysch3_wanshi") == 0 then
            player:throwAllCards("h")
        end
        if not target.dead  and (n < 3 or player:getMark("ysch3_wanshi") == 0) then
            room:recover({
            who = target,
            num = 1 - target.hp,
            recoverBy = player,
            skillName = self.name,
            })
        end
        if n < 1 or player:getMark("ysch3_wanshi") == 0 then
            local current = room.logic:getCurrentEvent()
            local death_event = current:findParent(GameEvent.Dying, true)
            death_event:addExitFunc(function ()
                if not room.current.dead then
                room:damage{
                    from = player,
                    to = room.current,
                    damage = 1,
                    skillName = self.name,
                }
                end
            end)
        end
    end,
}
jiangwei:addRelatedSkill(wanlan)
Fk:loadTranslationTable{
    ["ysch3_canfa"] = "残亻",
    [":ysch3_canfa"] = "出牌阶段，你可与一名其他角色拼点，若红牌赢，你可以令一名角色对指定目标发动“挑衅”；否则，你发动“困奋”并结束回合。",
    ["#ysch3_canfa_tiaoxin"] = "残亻：令一名角色对另一名角色发动“挑衅”",
    ["@ysch3_canfa_first"] = "挑衅",
    ["@ysch3_canfa_last"] = "被挑衅",
    ["ysch3_tiaoxin"] = "挑衅",
    [":ysch3_tiaoxin"] = "出牌阶段限一次，你可以指定一名你在其攻击范围内的角色，其需包括你在内的角色使用一张【杀】，否则你弃置其一张牌。",
    ["ysch3_kunfen"] = "困奋",
    [":ysch3_kunfen"] = "锁定技，结束阶段开始时，你失去1点体力，然后摸两张牌。",
    ["ysch3_wanshi"] = "挽执",
    [":ysch3_wanshi"] = "若你已损体力值不小于某一值，你视为拥有缺少对应项的“挽澜”。<br>1.伤害 2.弃牌 3.回复 4.限定技标签",
    ["ysch3_wanlan"] = "挽澜",
    [":ysch3_wanlan"] = "限定技，当一名角色进入濒死状态时，你可以发动此技能：弃置所有手牌，令其回复体力至1点，然后你对当前回合角色造成1点伤害。",

    ["$ysch3_canfa"] = "会成一腔凌云意，挥造万旌指北来！",
    ["$ysch3_tiaoxin_ysch3__jiangwei"] = "翻策打乱委鬼谶，命在剑台魂在麟！",
    ["$ysch3_kunfen_ysch3__jiangwei"] = "纵使困顿难行，亦当砥砺奋进！",
    ["$ysch3_wanshi"] = "涯腾麒麟骇邺乡，启明长庚昭成都！",
    ["$ysch3_wanlan_ysch3__jiangwei"] = "孤灯算尽将燃星，欲使龙庭岷倒流！",
    ["~ysch3__jiangwei"] = "丞...臣....",
}

local yuanshao = General:new(extension, "ysch3__yuanshao", "qun", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__yuanshao"] = "袁绍",
    ["#ysch3__yuanshao"] = "麟起佞讨",
    ["designer:ysch3__yuanshao"] = "铝",
    ["cv:ysch3__yuanshao"] = "佚名",
    ["illustrator:ysch3__yuanshao"] = "铁杵文化",
}
local dingzhi = fk.CreateViewAsSkill{
    name = "ysch3_dingzhi",
    prompt = "#ysch3_dingzhi",
    handly_pile = true,
    card_filter = function(self, to_select, selected)
        local card = Fk:getCardById(to_select)
        return #selected == 0 and (type(Self:getMark("ysch3_dingzhi-phase")) ~= "table" or not table.contains(Self:getMark("ysch3_dingzhi-phase"), card.suit))
    end,
    view_as = function(self, cards)
        if #cards ~= 1 then return end
        local card = Fk:cloneCard("slash")
        card:addSubcards(cards)
        card.skillName = "ysch3_dingzhi"
        return card
    end,
    before_use = function(self, player, use)
        use.extraUse = true
        local mark = type(player:getMark("ysch3_dingzhi-phase")) == "table" and player:getMark("ysch3_dingzhi-phase") or {}
        table.insert(mark, use.card.suit)
        player.room:setPlayerMark(player,"ysch3_dingzhi-phase",mark)
    end,
    enabled_at_play = function(self, player)
        local mark = player:getMark("ysch3_dingzhi-phase")
        return type(mark) ~= "table" or #mark < 4
    end,
    enabled_at_response = function(self, player, response)
        local mark = player:getMark("ysch3_dingzhi-phase")
        return not response and (type(mark) ~= "table" or #mark < 4)
    end,
}
local dingzhi_prohibit = fk.CreateProhibitSkill{
    name = "#ysch3_dingzhi_prohibit",
    is_prohibited = function(self, from, to, card)
        if table.contains(card.skillNames, "ysch3_dingzhi") then
            local tp = table.filter(Fk:currentRoom().alive_players, function(p)
                return p.seat == 1
            end)[1]
            return not to:inMyAttackRange(tp) or to:getAttackRange() < tp:getAttackRange()
        end
    end,
}
local dingzhi_buff = fk.CreateTargetModSkill{
    name = "#ysch3_dingzhi_buff",
    residue_func = function(self, player, skill, scope, card)
        return (player:hasSkill(self) and card and table.contains(card.skillNames, dingzhi.name)) and 999 or 0
    end,
    distance_limit_func = function(self, player, skill, card)
        return (player:hasSkill(self) and card and table.contains(card.skillNames, dingzhi.name)) and 999 or 0
    end,
}
dingzhi:addRelatedSkill(dingzhi_prohibit)
dingzhi:addRelatedSkill(dingzhi_buff)
yuanshao:addSkill(dingzhi)
Fk:addQmlMark{
    name = "ysch3_lixi",
    how_to_show = function(_, value)
        if type(value) ~= "table" then return " " end
        if value.loseHp then return Fk:translate("lose_hp") end
        if type(value.suits) ~= "table" or #value.suits == 0 then
            if value.dying then
                return "已造成濒死"
            else
                return " "
            end
        else
            local str = ""
            str = str..table.concat(table.map(value.suits, function(suit)
                return Fk:translate(Card.getSuitString({ suit = suit }, true))
            end), "")
            if value.dying then
                str = str.." √"
            end
            return str
        end
    end,
    qml_path = "",
}
local lixi = fk.CreateTriggerSkill{
    name = "ysch3_lixi",
    frequency = Skill.Quest,
    mute = true,
    events = {fk.RoundStart},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and player:getQuestSkillState(self.name) == nil and player.room:getBanner("RoundCount") >= 4
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player,"@[ysch3_lixi]",0)
        if event == fk.RoundStart then
            room:notifySkillInvoked(player, self.name, "negative")
            player:broadcastSkillInvoke(self.name, 2)
            room:handleAddLoseSkills(player, "-ysch3_dingzhi|ysch3_luanji")
            player:drawCards(player.maxHp, self.name)
            room:updateQuestSkillState(player, self.name, true)
            room:invalidateSkill(player, self.name)
        else
            room:notifySkillInvoked(player, self.name, "big")
            player:broadcastSkillInvoke(self.name, 1)
            room:handleAddLoseSkills(player, "-ysch3_dingzhi|ysch3_guixin|ysch3_zhaohan")
            room:updateQuestSkillState(player, self.name, false)
            room:invalidateSkill(player, self.name)
        end
    end,
}
local lixi_delay = fk.CreateTriggerSkill{
    name = "#ysch3_lixi_delay",
    refresh_events = {fk.CardUsing,fk.EnterDying},
    can_refresh = function (self, event, target, player, data)
        if player:hasSkill("ysch3_lixi") and player:getQuestSkillState("ysch3_lixi") == nil then
            if event == fk.CardUsing then
                return target == player and data.card.trueName == "slash" and data.card.suit ~= Card.NoSuit
            else
                return target ~= player and data.damage and data.damage.from == player
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local mark = type(player:getMark("@[ysch3_lixi]")) == "table" and player:getMark("@[ysch3_lixi]") or {
            suits = {},
            dying = false
        }
        if event == fk.CardUsing then
            if not table.contains(mark.suits,data.card.suit) then
                table.insert(mark.suits,data.card.suit)
            end
            room:setPlayerMark(player,"@[ysch3_lixi]",mark)
        else
            mark.dying = true
            room:setPlayerMark(player,"@[ysch3_lixi]",mark)
        end

        if #mark.suits > 3 and mark.dying then
            room:useSkill(player,lixi,function ()
                lixi:use(event, player, player, {})
            end,{})
        end
    end,
}
lixi:addRelatedSkill(lixi_delay)
yuanshao:addSkill(lixi)
local guixin = fk.CreateTriggerSkill{
    name = "ysch3_guixin",
    anim_type = "masochism",
    events = {fk.Damaged},
    on_trigger = function(self, event, target, player, data)
        self.cancel_cost = false
        for _ = 1, data.damage do
            if self.cancel_cost or not player:hasSkill(self) or
            table.every(player.room:getOtherPlayers(player, false), function (p) return p:isAllNude() end) then break end
            self:doCost(event, target, player, data)
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        if room:askForSkillInvoke(player, self.name, data) then
            room:doIndicate(player.id, table.map(room.alive_players, Util.IdMapper))
            return true
        end
        self.cancel_cost = true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        for _, p in ipairs(room:getOtherPlayers(player, true)) do
            if not p:isAllNude() then
            local id = room:askForCardChosen(player, p, "hej", self.name)
            room:obtainCard(player, id, false, fk.ReasonPrey)
            if player.dead then return false end
            end
        end
        player:turnOver()
    end,
}
local zhaohan = fk.CreateTriggerSkill{
    name = "ysch3_zhaohan",
    events = {fk.EventPhaseStart},
    frequency = Skill.Compulsory,
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Start and
        ((player:getMark(self.name) == 0 and player:isWounded()) or player:getMark(self.name) > 0)
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if player:getMark(self.name) == 0 then
            room:notifySkillInvoked(player, self.name, "support")
            room:recover({
                who = player,
                num = 1,
                recoverBy = player,
                skillName = self.name,
            })
        else
            room:notifySkillInvoked(player, self.name, "negative")
            room:loseHp(player, 1, self.name)
        end
    end,
  
    refresh_events = {fk.AfterDrawPileShuffle},
    can_refresh = function(self, event, target, player, data)
        return player:hasSkill(self, true)
    end,
    on_refresh = function(self, event, target, player, data)
        player.room:setPlayerMark(player, self.name, 1)
    end,
}
local luanji = fk.CreateViewAsSkill{
    name = "ysch3_luanji",
    anim_type = "offensive",
    pattern = "archery_attack",
    prompt = "#ysch3_luanji",
    handly_pile = true,
    card_filter = function(self, to_select, selected)
        if #selected == 1 then
            return table.contains(Self:getHandlyIds(), to_select) and Fk:getCardById(to_select).suit == Fk:getCardById(selected[1]).suit
        elseif #selected == 2 then
            return false
        end
        return table.contains(Self:getHandlyIds(), to_select)
    end,
    view_as = function(self, cards)
        if #cards ~= 2 then
            return nil
        end
        local c = Fk:cloneCard("archery_attack")
        c.skillName = self.name
        c:addSubcards(cards)
        return c
    end,
}
yuanshao:addRelatedSkill(guixin)
yuanshao:addRelatedSkill(zhaohan)
yuanshao:addRelatedSkill(luanji)
Fk:loadTranslationTable{
    ["ysch3_dingzhi"] = "鼎峙",
    [":ysch3_dingzhi"] = "每回合每种花色限一次，你可以将一张牌当做【杀】对攻击范围包含且不小于一号位的角色使用（无距离和次数限制）。",
    ["#ysch3_dingzhi"] = "鼎峙：将一张牌当【杀】使用",
    ["ysch3_lixi"] = "立檄",
    [":ysch3_lixi"] = "使命技，使用过四种花色的【杀】并令一名其他角色进入濒死状态。<br><b>成功</b>：你失去“鼎峙”并获得“归心”、“昭汉”。<br><b>失败</b>：第四轮开始时，你失去“鼎峙”并摸等同体力上限的牌，然后获得“乱击”。",
    ["@[ysch3_lixi]"] = "立檄",
    ["ysch3_guixin"] = "归心",
    [":ysch3_guixin"] = "当你受到1点伤害后，你可获得所有其他角色区域中的一张牌，然后你翻面。",
    ["ysch3_zhaohan"] = "昭汉",
    [":ysch3_zhaohan"] = "锁定技，准备阶段，若牌堆未洗过牌，你回复1点体力，否则你失去1点体力。",
    ["ysch3_luanji"] = "乱击",
    [":ysch3_luanji"] = "出牌阶段，你可以将任意两张相同花色的手牌当【万箭齐发】使用。",
    ["#ysch3_luanji"] = "乱击：你可以将两张相同花色的手牌当【万箭齐发】使用",

    ["$ysch3_dingzhi1"] = "你？不过是一篡逆之辈，又待怎样？！",
    ["$ysch3_dingzhi2"] = "吾剑未尝不利！",
    ["$ysch3_lixi1"] = "有吾袁氏坐镇，必保汉祚不衰！",
    ["$ysch3_lixi2"] = "大汉的心头之患不在外边，而是在诸位诸侯当中！",
    ["$ysch3_guixin_ysch3__yuanshao"] = "四世三公，自当高朋满座~",
    ["$ysch3_zhaohan_ysch3__yuanshao"] = "袁某健在一日，便保大汉昌盛一日！",
    ["$ysch3_luanji_ysch3__yuanshao1"] = "乱箭齐发，扫清异己！",
    ["$ysch3_luanji_ysch3__yuanshao2"] = "但有所见，一个不留！",
    ["~ysch3__yuanshao"] = "传...传主于...咳咳...于...袁......",
}

local shibao = General:new(extension, "ysch3__shibao", "jin", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__shibao"] = "石苞",
    ["#ysch3__shibao"] = "姿俊无双",
    ["designer:ysch3__shibao"] = "铝",
    ["cv:ysch3__shibao"] = "佚名",
    ["illustrator:ysch3__shibao"] = "凡果",
}
local zhuosheng = fk.CreateViewAsSkill{
    name = "ysch3_zhuosheng",
    prompt = function (self)
        if self.interaction.data then
            return "擢升：视为使用一张"..Fk:translate(Card.getSuitString({ suit = Util.getSuitFromString(self.interaction.data) }, true)).."A【杀】"
        else
            return "擢升：视为使用一张无色A点【杀】"
        end
    end,
    dynamic_desc = function (self, player, lang)
        local mark = type(player:getMark("ysch3_zhuosheng")) == "table" and player:getMark("ysch3_zhuosheng") or {}
        local arr, all_suits = {}, {"heart", "diamond", "club", "spade"}
        for _, v in ipairs(all_suits) do
            if type(mark) ~= "table" or not table.contains(mark,v) then
                table.insert(arr,Util.getSuitFromString(v))
            end
        end
        if #arr > 0 then
            return "你可视为使用一张："..table.concat(table.map(arr, function(suit)
                return Fk:translate(Card.getSuitString({ suit = suit }, true))
            end), "、").."A点【杀】，移除此花色并摸一张牌。其他角色只能使用上述含有的花色响应你使用的牌。"
        else
            return "你可视为使用一张A点【杀】。其他角色只能使用上述含有的花色响应你使用的牌。"
        end
    end,
    card_filter = Util.FalseFunc,
    interaction = function(self)
        local choices, choiceList = {}, {"heart", "diamond", "club", "spade"}
        local mark = Self:getMark("ysch3_zhuosheng")
        for _, v in ipairs(choiceList) do
            if type(mark) ~= "table" or not table.contains(mark,v) then
                table.insert(choices,"log_"..v)
            end
        end
        if #choices > 0 then
            return UI.ComboBox { choices = choices }
        else
            return nil
        end
    end,
    view_as = function(self, cards)
        if self.interaction.data then
            local card = Fk:cloneCard("slash",Util.getSuitFromString(self.interaction.data),1)
            card.skillName = "ysch3_zhuosheng"
            return card
        else
            local card = Fk:cloneCard("slash",nil,1)
            card.skillName = "ysch3_zhuosheng"
            return card
        end
    end,
    before_use = function(self, player, use)
        local room = player.room
        local mark = type(player:getMark("ysch3_zhuosheng")) == "table" and player:getMark("ysch3_zhuosheng") or {}
        table.insert(mark, Card.getSuitString(use.card))
        room:setPlayerMark(player,"ysch3_zhuosheng",mark)
        if use.card.suit ~= Card.NoSuit then
            player:drawCards(1,self.name)
        end

        local arr, all_suits = {}, {"heart", "diamond", "club", "spade"}
        for _, v in ipairs(all_suits) do
            if type(mark) ~= "table" or not table.contains(mark,v) then
                table.insert(arr,Util.getSuitFromString(v))
            end
        end
        room:setPlayerMark(player,"@ysch3_zhuosheng",table.concat(table.map(arr, function(suit)
            return Fk:translate(Card.getSuitString({ suit = suit }, true))
        end), " "))
    end,
    enabled_at_response = function(self, player, response)
        return not response
    end,
}
local zhuosheng_trigger = fk.CreateTriggerSkill{
    name = "#ysch3_zhuosheng_trigger",
    mute = true,
    events = {fk.CardUsing},
    can_trigger = function(self, event, target, player, data)
      return target == player and player:hasSkill("ysch3_zhuosheng")
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local targets = room:getOtherPlayers(player, false)
        local suits = type(player:getMark("ysch3_zhuosheng")) == "table" and player:getMark("ysch3_zhuosheng") or {}
        table.insert(suits,Card.NoSuit)
        data.extra_data = data.extra_data or {}
        data.extra_data.ysch3_zhuosheng_suits = data.extra_data.ysch3_zhuosheng_suits or {}
        room:notifySkillInvoked(player,"ysch3_zhuosheng","offensive")
        player:broadcastSkillInvoke("ysch3_zhuosheng")
        for _, p in ipairs(targets) do
            data.extra_data.ysch3_zhuosheng_suits[p.id] = suits
        end
    end,

    refresh_events = {fk.DrawInitialCards,fk.HandleAskForPlayCard},
    can_refresh = function(self, event, target, player, data)
        if event == fk.DrawInitialCards then
            return target == player and player:hasSkill(self.name, true)
        else
            if data.eventData and data.eventData.to == player.id then
                local dat = data.eventData.extra_data
                return dat and dat.ysch3_zhuosheng_suits and dat.ysch3_zhuosheng_suits[player.id]
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        if event == fk.DrawInitialCards then
            room:setPlayerMark(player,"@ysch3_zhuosheng",table.concat(table.map({Card.Heart, Card.Diamond, Card.Club, Card.Spade}, function(suit)
                return Fk:translate(Card.getSuitString({ suit = suit }, true))
            end), " "))
        else
            if not data.afterRequest then
                room:setBanner("ysch3_zhuosheng_suits", data.eventData.extra_data.ysch3_zhuosheng_suits[player.id])
            else
                room:setBanner("ysch3_zhuosheng_suits", nil)
            end
        end
    end,
}
local zhuosheng_prohibit = fk.CreateProhibitSkill{
    name = "#ysch3_zhuosheng_prohibit",
    prohibit_use = function(self, player, card)
        local suits = Fk:currentRoom():getBanner("ysch3_zhuosheng_suits")
        if suits then
            return table.contains(suits, card:getSuitString())
        end
    end,
    --[[prohibit_response = function(self, player, card)
        local suits = Fk:currentRoom():getBanner("ysch3_zhuosheng_suits")
        if suits then
            return table.contains(suits, card:getSuitString())
        end
    end,]]--
}
zhuosheng:addRelatedSkill(zhuosheng_trigger)
zhuosheng:addRelatedSkill(zhuosheng_prohibit)
shibao:addSkill(zhuosheng)
Fk:loadTranslationTable{
    ["ysch3_zhuosheng"] = "擢升",
    [":ysch3_zhuosheng"] = "你可视为使用一张：<font color='#CC3131'>♥</font>、<font color='#CC3131'>♦</font>、♣、♠A点【杀】，移除此花色并摸一张牌。其他角色只能使用上述含有的花色响应你使用的牌。",
    ["@ysch3_zhuosheng"] = "擢升",

    ["$ysch3_zhuosheng1"] = "才经世务，干用之绩。",
    ["$ysch3_zhuosheng2"] = "器量之远，当至公辅。",
}

local guotufengji = General:new(extension, "ysch3__guotufengji", "qun", 3, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__guotufengji"] = "郭图逢纪",
    ["#ysch3__guotufengji"] = "急急急军先行",
    ["designer:ysch3__guotufengji"] = "铝&cyc",
    ["cv:ysch3__guotufengji"] = "官方",
    ["illustrator:ysch3__guotufengji"] = "君桓文化",
}
local jigong = fk.CreateTriggerSkill{
    name = "ysch3_jigong",
    anim_type = "drawcard",
    events = {fk.TurnStart},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and target == player
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local choices = {}
        for i = 0, 3, 1 do
            table.insert(choices, tostring(i))
        end
        table.insert(choices,"Cancel")
        local choice = room:askForChoice(player, choices, self.name, "#ysch3_jigong-choice")
        if choice ~= "Cancel" then
            self.cost_data = tonumber(choice)
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        player:drawCards(self.cost_data, self.name)
        local num = 0
        if self.cost_data < 4 then
            for i = 1, 4 - self.cost_data, 1 do
                local use = U.askForUseVirtualCard(room, player, "ysch_Al__enemy_at_the_gates", nil, self.name, "#ysch3_jigong-use:::"..(4 - self.cost_data - i))
                if use then
                    if use.extra_data then
                        local useCard = use.extra_data.useSha or {}
                        p(useCard)
                        if i == 1 then
                            num = #useCard
                        end
                        if num > #useCard or num == 0 then
                            num = 0
                            break
                        end
                        num = #useCard
                    end
                else
                    break
                end
            end
        end
        --p(type(num))
        if num == 0 then
            player:gainAnExtraPhase(Player.Discard)
        end
        room:endTurn()
    end,
}
guotufengji:addSkill(jigong)
Fk:loadTranslationTable{
    ["ysch3_jigong"] = "急攻",
    [":ysch3_jigong"] = "回合开始时，你可以将回合改为：<br>摸至多三张牌，然后视为使用至多4-摸牌数张【兵临城下】（若本次使用【杀】的张数为零或少于本回合上次，则跳至弃牌阶段）。",
    ["#ysch3_jigong-choice"] = "急攻：请选择你要摸的牌数量",
    ["#ysch3_jigong-use"] = "急攻：视为使用一张【兵临城下】（还剩%arg张）",

    ["$ysch3_jigong1"] = "不惜一切代价，拿下此人！",
    ["$ysch3_jigong2"] = "曹贼势颓，主公速击之。",
}

local xunxu = General:new(extension, "ysch3z__xunxu", "jin", 3, 3, General.Male)--
Fk:loadTranslationTable{
    ["ysch3z"] = "宗族",
    ["ysch3z__xunxu"] = "族荀勖",
    ["#ysch3z__xunxu"] = "千变者假修",
    ["designer:ysch3z__xunxu"] = "铝",
    ["cv:ysch3z__xunxu"] = "妙啊",
    ["illustrator:ysch3z__xunxu"] = "佚名",
}
local erfeng_ban = {"steam__qisu","rfenghou__jianwang","rfenghou__jianwangg","rfenghou__bidao"}
local erfeng_give = fk.CreateActiveSkill{
    name = "ysch3_erfeng_give",
    expand_pile = function(self, player)
      return player:getTableMark("ysch3_erfeng_cards")
    end,
    min_card_num = 1,
    target_num = 1,
    card_filter = function(self, to_select, selected, targets)
      local ids = Self:getMark("ysch3_erfeng_cards")
        return type(ids) == "table" and table.contains(ids, to_select)
    end,
    target_filter = function(self, to_select, selected, _, _, _, player)
      return #selected == 0
    end,
}
Fk:addSkill(erfeng_give)
local erfeng = fk.CreateActiveSkill{
    name = "ysch3_erfeng",
    mute = true,
    target_num = 1,
    card_num = 0,
    target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
        return to_select ~= player.id
    end,
    card_filter = Util.FalseFunc,
    can_use = function (self, player, card, extra_data)
        return player:hasSkill(self.name) and player:usedSkillTimes(self.name,Player.HistoryRound) < 2 and player:usedSkillTimes("ysch3_erfeng",Player.HistoryPhase) < 1
    end,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        local to = room:getPlayerById(effect.tos[1])
        local player_skills = {}
        for _, skill in ipairs(player.player_skills) do
            if skill:isPlayerSkill(player) and not skill.name:startsWith("#") and not skill.attached_equip then
                table.insert(player_skills, skill.name)
            end
        end
        room:notifySkillInvoked(player,self.name)
        player:broadcastSkillInvoke(self.name,math.random(1,2))
        room:handleAddLoseSkills(player,"-"..player_skills[#player_skills],nil,true,false)
        --[[local mark_skills = type(player:getMark("ysch3_erfeng")) == "table" and player:getMark("ysch3_erfeng") or {}
        for i, v in ipairs(mark_skills) do
            if table.contains(v[2],player_skills[#player_skills]) then
                table.removeOne(v[2],player_skills[#player_skills])
                if #v[2] > 0 then
                    local realNames = table.map(v[2], Util.TranslateMapper)
                    local target = room:getPlayerById(v[1])
                    room:setPlayerMark(player,"@ysch3_erfeng_"..tostring(i),Fk:translate(target.general).." <font color='burlywood'>" .. table.concat(realNames, " ") .. "</font>")
                else
                    room:setPlayerMark(player,"@ysch3_erfeng_"..tostring(i),0)
                end
            end
        end]]--
        
        local cards = room:getCardsFromPileByRule(".|.|spade,club", 3, "discardPile")
        if #cards > 0 then
            room:setPlayerMark(player, "ysch3_erfeng_cards", cards)
            local _, ret = room:askForUseActiveSkill(player, "ysch3_erfeng_give", "#ysch3_erfeng-yiji", true, nil, true)
            if ret then
                for _, id in ipairs(ret.cards) do
                  table.removeOne(cards, id)
                end
                room:moveCardTo(ret.cards, Card.PlayerHand, room:getPlayerById(ret.targets[1]), fk.ReasonGive,
                self.name, nil, false, player.id, nil, player.id)
            end
            room:setPlayerMark(player, "ysch3_erfeng_cards", 0)

            if #cards > 0 then
                room:setPlayerMark(to, "ysch3_erfeng_cards", cards)
                local _, ret = room:askForUseActiveSkill(to, "ysch3_erfeng_give", "#ysch3_erfeng-yiji", true, nil, true)
                if ret then
                    for _, id in ipairs(ret.cards) do
                    table.removeOne(cards, id)
                    end
                    room:moveCardTo(ret.cards, Card.PlayerHand, room:getPlayerById(ret.targets[1]), fk.ReasonGive,
                    self.name, nil, false, to.id, nil, to.id)
                end
                room:setPlayerMark(to, "ysch3_erfeng_cards", 0)

                room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
            end
        end

        local to_skills = {}
        for _, skill in ipairs(to.player_skills) do
            if skill:isPlayerSkill(to) and not skill.name:startsWith("#") and not skill.attached_equip and not table.contains(erfeng_ban,skill.name) then
                table.insert(to_skills, skill.name)
            end
        end
        if #to_skills == 0 then return end
        table.insert(to_skills,"Cancel")
        local choice = room:askForChoice(to, to_skills, self.name, "#ysch3_erfeng-choice::"..player.id, true)
        if choice ~= "Cancel" then
            local skills = type(player:getMark("ysch3_erfeng")) == "table" and player:getMark("ysch3_erfeng") or {}
            local current = table.find(player.room.alive_players, function(p) return p.phase ~= Player.NotActive end)
            if current == nil then
                current = table.find(player.room.alive_players, function(p) return p.seat == 1 end)
            end
            if current ~= nil then
                local bool = true
                for i, v in ipairs(skills) do
                    if v[1] == current.id then
                        if not table.contains(v[2],choice) then
                            table.insert(v[2],choice)
                        end
                        bool = false
                        break
                    end
                end
                if bool == true then
                    table.insert(skills,{current.id,{choice}})
                end
            end
            room:handleAddLoseSkills(player, choice, nil, true, false)
            for i, v in ipairs(skills) do
                local cp = room:getPlayerById(v[1])
                if #v[2] > 0 then
                    local realNames = table.map(table.filter(v[2],function (s)
                        return player:hasSkill(s)
                    end), Util.TranslateMapper)
                    local loseNames = table.map(table.filter(v[2],function (s)
                        return not player:hasSkill(s)
                    end), Util.TranslateMapper)
                    if #realNames > 0 then
                        room:setPlayerMark(player,"@ysch3_erfeng_"..tostring(i),Fk:translate(cp.general).." <font color='burlywood'>" .. table.concat(realNames, " ") .. "</font>")
                    else
                        room:setPlayerMark(player,"@ysch3_erfeng_"..tostring(i),Fk:translate(cp.general).." <font color='gray'>" .. table.concat(loseNames, " ") .. "</font>")
                    end
                    --room:setPlayerMark(player,"@ysch3_erfeng_"..tostring(i),Fk:translate(cp.general).." <font color='burlywood'>" .. table.concat(realNames, " ") .. "</font>".." <font color='gray'>" .. table.concat(loseNames, " ") .. "</font>")
                else
                    room:setPlayerMark(player,"@ysch3_erfeng_"..tostring(i),0)
                end
            end

            room:setPlayerMark(player,"ysch3_erfeng",skills)
            --room:setPlayerMark(player,"ysch3_erfeng-turn",choice)
        end
    end,
}
local erfeng_trigger = fk.CreateTriggerSkill{
    name = "#ysch3_erfeng_trigger",
    events = {fk.EventPhaseStart},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill("ysch3_erfeng") and target ~= player and target.phase == Player.Start and player:usedSkillTimes("ysch3_erfeng",Player.HistoryRound) < 2
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local result = room:askForUseViewAsSkill(player,"ysch3_erfeng","#ysch3_erfeng-prompt",true)
        if result == true then
            local num = player:usedSkillTimes("ysch3_erfeng",Player.HistoryRound)
            player:setSkillUseHistory("ysch3_erfeng",num + 1,Player.HistoryRound)
        end
    end,

    refresh_events = {fk.TurnStart,fk.EventLoseSkill,fk.SkillEffect},
    can_refresh = function (self, event, target, player, data)
        local skills = type(player:getMark("ysch3_erfeng")) == "table" and player:getMark("ysch3_erfeng") or {}
        if #skills == 0 then return end
        if event == fk.TurnStart then
            for _, v in ipairs(skills) do
                if target.id == v[1] then
                    return true
                end
            end
        elseif event == fk.EventLoseSkill then
            if player == target then
                for _, v in ipairs(skills) do
                    for _, s in ipairs(v[2]) do
                        if not player:hasSkill(s) then
                            return true
                        end
                    end
                end
            end
        else
            if player == target and player:hasSkill(data.name) and not data.name:startsWith("#") then
                for _, v in ipairs(skills) do
                    for _, s in ipairs(v[2]) do
                        if s == data.name then
                            return true
                        end
                    end
                end
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        if event == fk.SkillEffect then
            player:broadcastSkillInvoke("ysch3_erfeng",math.random(3,4))
        else
            local skills = type(player:getMark("ysch3_erfeng")) == "table" and player:getMark("ysch3_erfeng") or {}
            if event == fk.TurnStart then
                for _, v in ipairs(skills) do
                    if v[1] == target.id then
                        for _, s in ipairs(v[2]) do
                            room:handleAddLoseSkills(player,"-"..s,nil,true,false)
                        end
                        v[2] = {}
                    end
                end
            end
            for i, v in ipairs(skills) do
                local current = room:getPlayerById(v[1])
                if #v[2] > 0 then
                    local realNames = table.map(table.filter(v[2],function (s)
                        return player:hasSkill(s)
                    end), Util.TranslateMapper)
                    local loseNames = table.map(table.filter(v[2],function (s)
                        return not player:hasSkill(s)
                    end), Util.TranslateMapper)
                    if #realNames > 0 then
                        room:setPlayerMark(player,"@ysch3_erfeng_"..tostring(i),Fk:translate(current.general).." <font color='burlywood'>" .. table.concat(realNames, " ") .. "</font>")
                    else
                        room:setPlayerMark(player,"@ysch3_erfeng_"..tostring(i),Fk:translate(current.general).." <font color='gray'>" .. table.concat(loseNames, " ") .. "</font>")
                    end
                    --room:setPlayerMark(player,"@ysch3_erfeng_"..tostring(i),Fk:translate(current.general).." <font color='burlywood'>" .. table.concat(realNames, " ") .. "</font>".." <font color='gray'>" .. table.concat(loseNames, " ") .. "</font>")
                else
                    room:setPlayerMark(player,"@ysch3_erfeng_"..tostring(i),0)
                end
            end

            room:setPlayerMark(player,"ysch3_erfeng",skills)
        end
    end,
}
erfeng:addRelatedSkill(erfeng_trigger)
xunxu:addSkill(erfeng)

local xunxu_win = fk.CreateActiveSkill{ name = "ysch3z__xunxu_win_audio" }
xunxu_win.package = extension
Fk:addSkill(xunxu_win)

local erfeng_banSkill = fk.CreateActiveSkill{ name = "ysch3_erfeng_ban" }
xunxu:addRelatedSkill(erfeng_banSkill)

if not Fk.skills["daojie"] then
    local daojie = fk.CreateTriggerSkill{
        name = "daojie",
        anim_type = "special",
        frequency = Skill.Compulsory,
        events = {fk.CardUseFinished},
        can_trigger = function(self, event, target, player, data)
            if player ~= target or not player:hasSkill(self) then return false end
            if not data.card:isCommonTrick() or data.card.is_damage_card then return false end
            local room = player.room
            local cardlist = data.card:isVirtual() and data.card.subcards or {data.card.id}
            if #cardlist == 0 or not table.every(cardlist, function (id)
                return room:getCardArea(id) == Card.Processing
            end) then return false end
            local logic = room.logic
            local use_event = logic:getCurrentEvent()
            local mark_name = "daojie_record-turn"
            local mark = player:getMark(mark_name)
            if mark == 0 then
                logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
                local last_use = e.data[1]
                if last_use.from == player.id and last_use.card:isCommonTrick() and not last_use.card.is_damage_card then
                    mark = e.id
                    room:setPlayerMark(player, mark_name, mark)
                    return true
                end
                return false
                end, Player.HistoryTurn)
            end
            return mark == use_event.id
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local skills = {}
            for _, skill in ipairs(player.player_skills) do
                if skill.frequency == Skill.Compulsory and skill:isPlayerSkill(player) then
                table.insert(skills, skill.name)
                end
            end
            table.insert(skills, "loseHp")
            local choice = room:askForChoice(player, skills, self.name, "#daojie-choice", true)
            if choice == "loseHp" then
                room:loseHp(player, 1, self.name)
            else
                room:handleAddLoseSkills(player, "-"..choice, nil, true, false)
            end
            if not player.dead and table.every(Card:getIdList(data.card), function (id)
                return room:getCardArea(id) == Card.Processing
            end) then
                local targets = {}
                for _, p in ipairs(room.alive_players) do
                if isFamilyMember(p, "xun") or player == p then
                    table.insert(targets, p.id)
                end
                end
                --理论上不会为空（必定包含自己）
                if #targets > 1 then
                targets = room:askForChoosePlayers(player, targets, 1, 1, "#daojie-choose:::"..data.card:toLogString(), self.name, false)
                end
                room:obtainCard(targets[1], data.card, true, fk.ReasonPrey)
            end
        end,
    }
    Fk:addSkill(daojie)
    Fk:loadTranslationTable{
        ["daojie"] = "蹈节",
        [":daojie"] = "宗族技，锁定技，当你每回合首次使用非伤害类普通锦囊牌后，你选择一项：1.失去1点体力；2.失去一个锁定技。然后令一名同族角色获得此牌。",
        ["#daojie-choice"] = "蹈节：选择失去一个锁定技，或失去1点体力",
        ["#daojie-choose"] = "蹈节：令一名同族角色获得此%arg",
        ["daojie_cancel"] = "取消",
        [":daojie_cancel"] = "失去1点体力",
    }
end
xunxu:addSkill("daojie")

Fk:loadTranslationTable{
    ["ysch3_erfeng"] = "貮逢",
    ["ysch3_erfeng_give"] = "貮逢",
    ["#ysch3_erfeng_trigger"] = "貮逢",
    ["@ysch3_erfeng_1"] = "",
    ["@ysch3_erfeng_2"] = "",
    ["@ysch3_erfeng_3"] = "",
    ["@ysch3_erfeng_4"] = "",
    ["@ysch3_erfeng_5"] = "",
    ["@ysch3_erfeng_6"] = "",
    ["@ysch3_erfeng_7"] = "",
    ["@ysch3_erfeng_8"] = "",
    ["@ysch3_erfeng_9"] = "",
    ["@ysch3_erfeng_10"] = "",
    [":ysch3_erfeng"] = "每轮限两次，其他角色准备阶段或出牌阶段限一次，你可以失去最下端的一个技能，发现弃牌堆的黑色牌并与一名其他角色各分配至多一张，然后其可声明其的一个技能，令你获得至当前回合角色的下个回合开始。",
    ["#ysch3_erfeng-yiji"] = "貮逢：你可以分配其中一张牌",
    ["#ysch3_erfeng-prompt"] = "是否发动 貮逢，失去最下端的一个技能并有机会分配黑色牌和再获得一个技能",
    ["#ysch3_erfeng-choice"] = "貮逢：你可以令%dest获得其中一个技能",
    ["ysch3_erfeng_ban"] = "ban技能池",
    [":ysch3_erfeng_ban"] = "<a href=':steam__qisu'>弃俗</a>、<a href=':rfenghou__jianwang'>鉴往</a>、<a href=':rfenghou__bidao'>彼道</a>",

    ["$ysch3_erfeng1"] = "君行其道，臣恪其守，君命臣从，何贰之有？",
    ["$ysch3_erfeng2"] = "谓我大失物情？物情不足恤，岂不更闻有上意~",
    ["$ysch3_erfeng3"] = "茂先好才气！然台辅之位，非尔所宜居也~",
    ["$ysch3_erfeng4"] = "承祚好笔头，既作国史诸卷，且任长广太守。",
    ["$daojie_ysch3z__xunxu1"] = "人臣不密，必致失身，安可自取祸由？",
    ["$daojie_ysch3z__xunxu2"] = "树私背公，必遭天诛，当戒之，当戒之！",
    ["~ysch3z__xunxu"] = "夺我凤凰池，如何不怏怏。",
    ["ysch3z__xunxu_win_audio"] = "胜利语音",
    ["$ysch3z__xunxu_win_audio"] = "解人所未解，居人所不居。",
}

local litong = General:new(extension, "ysch3__litong", "wei", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__litong"] = "李通",
    ["#ysch3__litong"] = "推心置腹",
    ["designer:ysch3__litong"] = "铝",
    ["cv:ysch3__litong"] = "官方",
    ["illustrator:ysch3__litong"] = "枭瞳",
}
local tuifeng = fk.CreateActiveSkill{
    name = "ysch3_tuifeng",
    prompt = "#ysch3_tuifeng",
    min_card_num = 1,
    max_card_num = 4,
    target_num = 1,
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
        if #selected_cards > 0 then
            local to = Fk:currentRoom():getPlayerById(to_select)
            return #player:getCardIds({Player.Hand, Player.Equip}) + #to:getCardIds({Player.Hand, Player.Equip}) >= 4 and to ~= player
        end
    end,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        local to = room:getPlayerById(effect.tos[1])
        local num = 4 - #effect.cards
        local cards = {}
        local sha1 , sha2 = #table.filter(effect.cards,function (id)
            local c = Fk:getCardById(id)
            return c.trueName == "slash"
        end), 0
        table.insertTable(cards,effect.cards)
        player:showCards(effect.cards)
        local whileI = 1
        while #cards < 4 do
            if #table.filter(to:getCardIds("he"),function (id)
                return not table.contains(cards,id)
            end) > 0 then
                local shows = room:askForCard(to,1,num,true,self.name,false,tostring(Exppattern{ id = table.filter(to:getCardIds("he"),function (id)
                    return not table.contains(cards,id)
                end) }),"#ysch3_tuifeng-show:::"..tostring(num))
                if #shows > 0 then
                    to:showCards(shows)
                    table.insertTable(cards,shows)
                    sha2 = sha2 + #table.filter(shows,function (id)
                        local c = Fk:getCardById(id)
                        return c.trueName == "slash"
                    end)
                end
            end
            if #cards >= 4 then break end
            if #table.filter(player:getCardIds("he"),function (id)
                return not table.contains(cards,id)
            end) > 0 then
                local shows2 = room:askForCard(player,1,num,true,self.name,false,tostring(Exppattern{ id = table.filter(player:getCardIds("he"),function (id)
                    return not table.contains(cards,id)
                end) }),"#ysch3_tuifeng-show:::"..tostring(num))
                if #shows2 > 0 then
                    player:showCards(shows2)
                    table.insertTable(cards,shows2)
                    sha1 = sha1 + #table.filter(shows2,function (id)
                        local c = Fk:getCardById(id)
                        return c.trueName == "slash"
                    end)
                end
            end

            whileI = whileI + 1

            if whileI > 4 then break end
        end
        room:moveCardTo(cards, Card.DrawPile, player, fk.ReasonPut, self.name, nil, true)

        if sha1 > sha2 then
            room:useVirtualCard("ysch_Al__enemy_at_the_gates", nil, player, to, self.name)
        elseif sha2 > sha1 then
            room:useVirtualCard("ysch_Al__enemy_at_the_gates", nil, to, player, self.name)
        end
    end,
}
litong:addSkill(tuifeng)
Fk:loadTranslationTable{
    ["ysch3_tuifeng"] = "推锋",
    [":ysch3_tuifeng"] = "出牌阶段限一次，你可以与一名其他角色依次展示至少一张不重复的牌，直至共展示四张牌，然后你将这些牌置于牌堆顶，展示【杀】较多一方视为对另一方使用【兵临城下】。",
    ["#ysch3_tuifeng"] = "推锋：与一名其他角色依次展示共计四张牌，展示【杀】更多的角色对另一方使用【兵临城下】",
    ["#ysch3_tuifeng-show"] = "推锋：展示至多%arg张牌，展示【杀】更多的角色对另一方使用【兵临城下】",

    ["$ysch3_tuifeng1"] = "看吾提枪策马，一击必杀！",
    ["$ysch3_tuifeng2"] = "敌随千万，吾亦独往！",
}

local waner = General:new(extension, "ysch3__shangguanwaner", "tang", 3, 3, General.Female)--
Fk:loadTranslationTable{
    ["ysch3__shangguanwaner"] = "上官婉儿",
    ["#ysch3__shangguanwaner"] = "黥妆才媛",
    ["designer:ysch3__shangguanwaner"] = "铝",
    ["cv:ysch3__shangguanwaner"] = "无",
    ["illustrator:ysch3__shangguanwaner"] = "未知",
}
local caiqi = fk.CreateTriggerSkill{
    name = "ysch3_caiqi",
    events = {fk.CardUseFinished},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) and target == player and data.card.type ~= Card.TypeEquip then
            return type(player:getMark("ysch3_caiqi-turn")) ~= "table" or #player:getMark("ysch3_caiqi-turn") < 4
        end
    end,
    mute = true,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local choices = {}
        local mark = type(player:getMark("ysch3_caiqi-turn")) == "table" and player:getMark("ysch3_caiqi-turn") or {}
        if not table.contains(mark,"#ysch3_caiqi-choice1") and not player.chained then
            table.insert(choices,"#ysch3_caiqi-choice1")
        end
        if not table.contains(mark,"#ysch3_caiqi-choice2") and player:getHandcardNum() ~= #GetShownCards(player) then
            table.insert(choices,"#ysch3_caiqi-choice2")
        end
        if not table.contains(mark,"#ysch3_caiqi-choice3") and player.faceup then
            table.insert(choices,"#ysch3_caiqi-choice3")
        end
        if not table.contains(mark,"#ysch3_caiqi-choice4") and not player:isAllNude() then
            table.insert(choices,"#ysch3_caiqi-choice4")
        end
        if #choices > 0 then
            table.insert(choices,"Cancel")
            local result = room:askForChoice(player,choices,self.name,"#ysch3_caiqi",false,{"#ysch3_caiqi-choice1","#ysch3_caiqi-choice2","#ysch3_caiqi-choice3","#ysch3_caiqi-choice4","Cancel"})
            if result ~= "Cancel" then
                self.cost_data = result
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local choice = self.cost_data
        local mark = type(player:getMark("ysch3_caiqi-turn")) == "table" and player:getMark("ysch3_caiqi-turn") or {}
        table.insert(mark,choice)
        room:setPlayerMark(player,"ysch3_caiqi-turn",mark)
        local all_index = {" 壹"," 贰"," 叁"," 肆"}
        room:setPlayerMark(player,"@ysch3_caiqi-turn",all_index[#mark])
        room:notifySkillInvoked(player,self.name)
        switch(choice,{
            ["#ysch3_caiqi-choice1"] = function()
                player:broadcastSkillInvoke(self.name,1)
                player:setChainState(true)
            end,
            ["#ysch3_caiqi-choice2"] = function()
                player:broadcastSkillInvoke(self.name,2)
                for _, id in ipairs(player:getCardIds("h")) do
                    room:setCardMark(Fk:getCardById(id), '@@ShownCards-inhand', 1)
                end
            end,
            ["#ysch3_caiqi-choice3"] = function()
                player:broadcastSkillInvoke(self.name,3)
                player:turnOver()
            end,
            ["#ysch3_caiqi-choice4"] = function()
                player:broadcastSkillInvoke(self.name,4)
                local choices, all_choices = {}, {"$Hand","$Equip","$Judge"}
                for i, v in ipairs({"h", "e", "j"}) do
                    if #player:getCardIds(v) > 0 then
                        table.insert(choices, all_choices[i])
                    end
                end
                local choice = room:askForChoice(player, choices, self.name,"#ysch3_caiqi-recast",false,all_choices)
                if choice == "$Hand" then
                    room:recastCard(player:getCardIds("h"), player, self.name)
                elseif choice == "$Equip" then
                    room:recastCard(player:getCardIds("e"), player, self.name)
                elseif choice == "$Judge" then
                    room:recastCard(player:getCardIds("j"), player, self.name)
                end
            end,
        })

        if #mark >= 4 and player:getMark("ysch_Al__adaptation-turn") ~= 0 then
            local c = Fk:cloneCard(player:getMark("ysch_Al__adaptation-turn"))
            if not player:prohibitUse(c) then
                player:broadcastSkillInvoke(self.name,5)
                U.askForUseVirtualCard(room,player,c.name,nil,self.name,"#ysch3_caiqi-use:::"..c.name)
            end
        end
    end,
}
waner:addSkill(caiqi)
local qingmei = fk.CreateActiveSkill{
    name = "ysch3_qingmei",
    prompt = "#ysch3_qingmei",
    anim_type = "masochism",
    mute = true,
    card_num = 0,
    target_num = 0,
    card_filter = Util.FalseFunc,
    interaction = function(self)
        local choices = {}
        if Self.chained then
            table.insert(choices,"#ysch3_qingmei-choice1")
        end
        if not Self.faceup then
            table.insert(choices,"#ysch3_qingmei-choice2")
        end
        if Self:getMaxCards() > 0 then
            table.insert(choices,"#ysch3_qingmei-choice3")
        end
        return UI.ComboBox {choices = choices, all_choices = {"#ysch3_qingmei-choice1","#ysch3_qingmei-choice2","#ysch3_qingmei-choice3"}}
    end,
    can_use = function (self, player, card, extra_data)
        return #table.filter(player:getCardIds(Player.Judge), function(id)
            local c = player:getVirualEquip(id)
            if c and string.find(c.name,"premeditate") then return true end
            return false
          end) < 3 and (player.chained or not player.faceup or player:getMaxCards() > 0)
    end,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        local choice = self.interaction.data
        local cards = room:getCardsFromPileByRule(".|.|club", 3, "allPiles")
        local result = room:askForCardChosen(player, player, { card_data = { { self.name, table.random(cards, 3) } } }, self.name, "#ysch3_qingmei-card")
        room:notifySkillInvoked(player,self.name)
        premeditate (player, result, self.name, player.id)
        switch(choice,{
            ["#ysch3_qingmei-choice1"] = function()
                player:broadcastSkillInvoke(self.name,1)
                player:setChainState(false)
            end,
            ["#ysch3_qingmei-choice2"] = function()
                player:broadcastSkillInvoke(self.name,2)
                player:turnOver()
            end,
            ["#ysch3_qingmei-choice3"] = function()
                player:broadcastSkillInvoke(self.name,3)
                room:addPlayerMark(player, "@ysch3_qingmei-turn", 1)
                local n = player:getMaxCards() - player:getHandcardNum()
                if n > 0 then
                    player:drawCards(n,self.name)
                elseif n < 0 then
                    room:askForDiscard(player,-n,-n,false,self.name,false,nil,"#ysch3_qingmei-discard:::"..player:getMaxCards())
                end
            end,
        })
    end,
}
local qingmei_maxcards = fk.CreateMaxCardsSkill{
    name = "#ysch3_qingmei_maxcards",
    correct_func = function(self, player)
      return -player:getMark("@ysch3_qingmei-turn")
    end,
}
local qingmei_trigger = fk.CreateTriggerSkill{
    name = "#ysch3_qingmei_trigger",
    events = {fk.Damaged},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill("ysch3_qingmei") and target == player and #table.filter(player:getCardIds(Player.Judge), function(id)
            local c = player:getVirualEquip(id)
            if c and string.find(c.name,"premeditate") then return true end
            return false
          end) < 3 and (player.chained or not player.faceup or player:getMaxCards() > 0)
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local result = room:askForUseViewAsSkill(player,"ysch3_qingmei","#ysch3_qingmei",true)
        if result == true then
        end
    end,
}
qingmei:addRelatedSkill(qingmei_maxcards)
qingmei:addRelatedSkill(qingmei_trigger)
waner:addSkill(qingmei)
local waner_win = fk.CreateActiveSkill{ name = "ysch3__shangguanwaner_win_audio" }
waner_win.package = extension
Fk:addSkill(waner_win)
Fk:loadTranslationTable{
    ["ysch3_caiqi"] = "才绮",
    [":ysch3_caiqi"] = "每回合每项各限一次，你使用非装备牌结算完成后，可：1.横置；2.明置手牌；3.翻至背面；4.重铸一个区域。若本回合均执行，你可<a href='ysch3_caiqi-adaptation'>视为使用【随机应变】</a>。",
    ["ysch3_caiqi-adaptation"] = "<b>视为使用【随机应变】</b>：实际上就是视为使用你本回合使用或打出的上一张基本牌或普通锦囊牌。",
    ["#ysch3_caiqi-choice1"] = "横置",
    ["#ysch3_caiqi-choice2"] = "明置手牌",
    ["#ysch3_caiqi-choice3"] = "翻至背面",
    ["#ysch3_caiqi-choice4"] = "重铸一个区域",
    ["@ysch3_caiqi-turn"] = "才绮",
    ["#ysch3_caiqi"] = "是否发动 才绮，执行以下一项？",
    ["#ysch3_caiqi-recast"] = "才绮：重铸一个区域",
    ["#ysch3_caiqi-use"] = "才绮：视为使用【随机应变】（%arg）",
    ["ysch3_qingmei"] = "黥梅",
    [":ysch3_qingmei"] = "出牌阶段或当你受到伤害后，若你的蓄谋牌数小于3，你可以发现一张♣牌蓄谋并：1.重置连环状态；2.翻至正面；3.本回合手牌上限-1并将手牌调整至上限。",
    ["#ysch3_qingmei-choice1"] = "重置连环状态",
    ["#ysch3_qingmei-choice2"] = "翻至正面",
    ["#ysch3_qingmei-choice3"] = "调整手牌及上限",
    ["@ysch3_qingmei-turn"] = "黥梅",
    ["#ysch3_qingmei_trigger"] = "黥梅",
    ["#ysch3_qingmei"] = "黥梅：发现一张♣牌蓄谋并执行一项",
    ["#ysch3_qingmei-card"] = "选择一张牌蓄谋",
    ["#ysch3_qingmei-discard"] = "黥梅：将手牌调整至%arg",

    ["$ysch3_caiqi1"] = "逆风起笔，最能得势。",
    ["$ysch3_caiqi2"] = "言为心声，字为心画。",
    ["$ysch3_caiqi3"] = "笔落兴亡，定三端之妙。",
    ["$ysch3_caiqi4"] = "墨写清白，尽六艺之奥。",
    ["$ysch3_caiqi5"] = "不择纸笔，妙在心手。",
    ["$ysch3_qingmei1"] = "弱小的女孩不会永远弱小。",
    ["$ysch3_qingmei2"] = "百孔千疮，复原必当如初。",
    ["$ysch3_qingmei3"] = "以己为墨，重构山河。",
    ["ysch3__shangguanwaner_win_audio"] = "胜利语音",
    ["$ysch3__shangguanwaner_win_audio"] = "哎~这歪歪扭扭的字体，就像你歪歪扭扭的人生一样糟糕。",
    ["~ysch3__shangguanwaner"] = "紫毫已折……",
}
local sunru = General:new(extension, "ysch3__sunru", "wu", 3, 3, General.Female)--
Fk:loadTranslationTable{
    ["ysch3__sunru"] = "孙茹",
    ["#ysch3__sunru"] = "呦呦鹿鸣",
    ["designer:ysch3__sunru"] = "铝&朱苦力&伶伶",
    ["cv:ysch3__sunru"] = "官方",
    ["illustrator:ysch3__sunru"] = "花地",
}
local yingjian = fk.CreateViewAsSkill{
    name = "ysch3_yingjian",
    anim_type = "offensive",
    prompt = "#ysch3_yingjian",
    pattern = "slash,archery_attack",
    interaction = function()
        local choices, all_choices = {}, {"ysch_Al_shot__slash","archery_attack"}
        for _, name in ipairs(all_choices) do
            if Fk.currentResponsePattern == nil or Exppattern:Parse(Fk.currentResponsePattern):match(Fk:cloneCard(name)) then
                table.insert(choices, name)
            end
        end
        if #choices > 0 then
            return U.CardNameBox { choices = choices }
        end
    end,
    handly_pile = true,
    card_filter = function(self, to_select, selected)
        local c = Fk:getCardById(to_select)
        if self.interaction.data then
            if self.interaction.data == "ysch_Al_shot__slash" then
                return #selected == 0 and string.find(c.name,"shade")
            else
                return #selected < 3 and string.find(c.name,"shade")
            end
        end
    end,
    view_as = function (self, cards, player)
        if #cards == 0 or not self.interaction.data then return end
        if self.interaction.data == "archery_attack" and #cards < 3 then
            return nil
        end
        local card = Fk:cloneCard(self.interaction.data)
        card:addSubcards(cards)
        card.skillName = self.name
        return card
    end,
}
sunru:addSkill(yingjian)
local qingyi = fk.CreateTriggerSkill{
    name = "ysch3_qingyi",
    anim_type = "defensive",
    events = {fk.EventPhaseChanging,fk.DamageInflicted,fk.CardUsing},
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(self) then
            if event == fk.EventPhaseChanging then
                return data.to == Player.Judge
            elseif event == fk.DamageInflicted then
                return data.damageType == fk.FireDamage
            else
                return data.card.type == Card.TypeEquip
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local str = "#ysch3_qingyi-choose1"
        if event == fk.DamageInflicted then
            str = "#ysch3_qingyi-choose2"
        elseif event == fk.CardUsing then
            str = "#ysch3_qingyi-choose3"
        end
        if player.room:askForSkillInvoke(player,self.name,nil,str) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local use = room:askForUseCard(player, "slash", "slash", "#ysch3_qingyi-slash", true)
        if use then
            use.extraUse = true
            room:useCard(use)
        else
            room:moveCardTo(getShade(room, 1), Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
        end
        if event == fk.EventPhaseChanging then
            player:skip(Player.Judge)
        elseif event == fk.DamageInflicted then
            return true
        else
            data.toCard = nil
            data.tos = {}
        end
    end,
}
sunru:addSkill(qingyi)
Fk:loadTranslationTable{
    ["ysch3_yingjian"] = "影箭",
    [":ysch3_yingjian"] = "你可以将一/三张【影】当射【杀】/【万箭齐发】使用。",
    ["#ysch3_yingjian"] = "影箭：将一/三张【影】当射【杀】/【万箭齐发】使用",
    ["ysch3_qingyi"] = "轻逸",
    [":ysch3_qingyi"] = "判定阶段开始，或受到火焰伤害时，或使用装备牌时，可改为获得一张【影】或使用一张【杀】。",
    ["#ysch3_qingyi-slash"] = "轻逸：使用一张【杀】，或获得一张【影】",
    ["#ysch3_qingyi-choose1"] = "轻逸：你可以跳过判定阶段，获得一张【影】或使用一张【杀】",
    ["#ysch3_qingyi-choose2"] = "轻逸：你可以防止此伤害，获得一张【影】或使用一张【杀】",
    ["#ysch3_qingyi-choose3"] = "轻逸：你可以取消此牌目标，获得一张【影】或使用一张【杀】",

    ["$ysch3_yingjian1"] = "纤纤碧玉，轻逸如虹。",
    ["$ysch3_yingjian2"] = "舞袖轻婳语，玉容绝尘颜。",
    ["$ysch3_qingyi1"] = "谦恭以释嫌隙，静默而破霜雪。",
    ["$ysch3_qingyi2"] = "释之宽忍，衅以禅让。",
}
local zhangchunhua = General:new(extension, "ysch3__zhangchunhua", "wei", 3, 3, General.Female)--
Fk:loadTranslationTable{
    ["ysch3__zhangchunhua"] = "张春华",
    ["#ysch3__zhangchunhua"] = "寒心断念",
    ["designer:ysch3__zhangchunhua"] = "铝&yyuaN",
    ["cv:ysch3__zhangchunhua"] = "官方",
    ["illustrator:ysch3__zhangchunhua"] = "小罗没想好",
}
local shuangxue = fk.CreateTriggerSkill{
    name = "ysch3_shuangxue",
    mute = true,
    anim_type = "defensive",
    events = {"fk.GeneralAppeared"},
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasShownSkill(self)
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local use = room:askForUseCard(player, "slash", "slash", "#ysch3_shuangxue-slash", true)
        room:notifySkillInvoked(player,self.name,"defensive")
        if use then
            use.extraUse = true
            room:useCard(use)
        end
        local mark = type(player:getMark("@[player]ysch3_shuangxue")) == "table" and player:getMark("@[player]ysch3_shuangxue") or {}
        if table.contains(mark,room.current.id) then
            room:damage{
                from = target,
                to = target,
                damage = 1,
                damageType = fk.IceDamage,
                skillName = self.name,
            }
        else
            table.insert(mark,room.current.id)
        end
        room:setPlayerMark(player,"@[player]ysch3_shuangxue",mark)
    end,

    refresh_events = {fk.GameFinished},
    can_refresh = function(self, event, target, player, data)
        return player:getMark("__hidden_general") ~= 0 or player:getMark("__hidden_deputy") ~= 0
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local p = player
        room:handleAddLoseSkills(p, "-hidden_skill&", nil, false, true)
        if Fk.generals[p:getMark("__hidden_general")] then
            p.general = p:getMark("__hidden_general")
        end
        if Fk.generals[p:getMark("__hidden_deputy")] then
            p.deputyGeneral = p:getMark("__hidden_deputy")
        end
        room:setPlayerMark(p, "__hidden_general", 0)
        room:setPlayerMark(p, "__hidden_deputy", 0)
        local general = Fk.generals[p.general]
        local deputy = Fk.generals[p.deputyGeneral]
        p.gender = general.gender
        p.kingdom = general.kingdom
        room:broadcastProperty(p, "gender")
        room:broadcastProperty(p, "general")
        room:broadcastProperty(p, "deputyGeneral")
        room:askForChooseKingdom({p})
        room:broadcastProperty(p, "kingdom")
        
        p.maxHp = p:getGeneralMaxHp()
        p.hp = deputy and math.floor((deputy.hp + general.hp) / 2) or general.hp
        p.shield = math.min(general.shield + (deputy and deputy.shield or 0), 5)
        local changer = Fk.game_modes[room.settings.gameMode]:getAdjustedProperty(p)
        if changer then
            for key, value in pairs(changer) do
                p[key] = value
            end
        end
        room:broadcastProperty(p, "maxHp")
        room:broadcastProperty(p, "hp")
        room:broadcastProperty(p, "shield")

        local lordBuff = p.role == "lord" and p.role_shown == true and #room.players > 4
        local skills = general:getSkillNameList(lordBuff)
        if deputy then
            table.insertTable(skills, deputy:getSkillNameList(lordBuff))
        end
        skills = table.filter(skills, function (s)
            local skill = Fk.skills[s]
            return skill and (#skill.attachedKingdom == 0 or table.contains(skill.attachedKingdom, p.kingdom))
        end)
        if #skills > 0 then
            room:handleAddLoseSkills(p, table.concat(skills, "|"), nil, false)
        end

        room:sendLog{ type = "#RevealGeneral", from = p.id, arg =  "mainGeneral", arg2 = general.name }
        local event_data = {["m"] = general}
        if deputy then
            room:sendLog{ type = "#RevealGeneral", from = p.id, arg =  "deputyGeneral", arg2 = deputy.name }
            event_data["d"] = deputy.name
        end
        --room.logic:trigger("fk.GeneralAppeared", p, event_data)
    end,
}
shuangxue.isHiddenSkill = true
zhangchunhua:addSkill(shuangxue)
local henli = fk.CreateViewAsSkill{
    name = "ysch3_henli",
    anim_type = "defensive",
    pattern = "slash",
    card_filter = function(self, to_select, selected)
        return #selected < 1
    end,
    view_as = function(self, cards)
        if #cards ~= 1 then
            return nil
        end
        self._extra_data.cards = cards
        local c = Fk:cloneCard("slash")
        c.skillName = self.name
        return c
    end,
    before_use = function(self, player, use)
        use.extraUse = true
        local room = player.room
        local yinni = false
        room:recastCard(self._extra_data.cards, player, self.name)
        for _, id in ipairs(TargetGroup:getRealTargets(use.tos)) do
            local to = room:getPlayerById(id)
            to:setChainState(true)
        end
        for _, id in ipairs(TargetGroup:getRealTargets(use.tos)) do
            local to = room:getPlayerById(id)
            local recastCards = room:askForCard(to, 1, 1, true, self.name, true, ".", "#ysch3_henli-card::"..player.id)
            if #recastCards > 0 then
                yinni = true
                room:recastCard(recastCards, to, self.name)
                player:setChainState(true)
            end
        end
        if yinni == true and not player.dead then
            if player.general ~= "hiddenone" and ((player.deputyGeneral ~= "" and player.deputyGeneral ~= "hiddenone") or not player.deputyGeneral ~= "" ) then
                DIYEnterHidden(player)
            end
            room:broadcastPlaySound("./packages/ysch_Al/audio/show/ysch3__zhangchunhua_"..tostring(math.random(1,2)))
        end
    end,
    enabled_at_play = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
    end,
    enabled_at_response = function(self, player, response)
        return not response and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
    end,
}
local henli_buff = fk.CreateTargetModSkill{
    name = "#ysch3_henli_buff",
    residue_func = function(self, player, skill, scope, card)
      return (player:hasSkill(self) and card and table.contains(card.skillNames, henli.name)) and 999 or 0
    end,
    distance_limit_func = function(self, player, skill, card)
      return (player:hasSkill(self) and card and table.contains(card.skillNames, henli.name)) and 999 or 0
    end,
}
henli:addRelatedSkill(henli_buff)
zhangchunhua:addSkill(henli)
Fk:loadTranslationTable{
    ["ysch3_shuangxue"] = "霜血",
    [":ysch3_shuangxue"] = "隐匿。你登场后，可使用一张【杀】。若你在当前回合角色的回合登场过，你对自己造成1点冰冻伤害。",
    ["#ysch3_shuangxue-slash"] = "霜血：你可以使用一张【杀】",
    ["@[player]ysch3_shuangxue"] = "霜血",
    ["ysch3_henli"] = "恨离",
    [":ysch3_henli"] = "每回合限一次，当你需要使用无次数和距离限制的【杀】时，你可以重铸一张牌再横置对方视为使用之，其也可以对你如此做，然后你隐匿。",
    ["#ysch3_henli-card"] = "恨离：你可以重铸一张牌，并横置%dest",

    ["$ysch3_shuangxue1"] = "博弈此生，终至无情。",
    ["$ysch3_shuangxue2"] = "此情已逝，故来决绝！",
    ["$ysch3_henli1"] = "情随伤而逝，恨随痛而至！",
    ["$ysch3_henli2"] = "春华已老红颜去，此恨绵绵无绝期。",
    ["~ysch3__zhangchunhua"] = "不怕花容去，只怕情难续。",
}
--[[local simayi = General:new(extension, "ysch3__simayi", "wei", 3, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__simayi"] = "司马懿",
    ["#ysch3__simayi"] = "狼日凌穹",
    ["designer:ysch3__simayi"] = "铝&永乐",
    ["cv:ysch3__simayi"] = "官方",
    ["illustrator:ysch3__simayi"] = "佚名",
}
Fk:addQmlMark{
    name = "ysch3__shefu",
    how_to_show = function(name, value, p)
        if type(value) ~= "table" then return " " end
        return tostring(#value)
    end,
    qml_path = function(name, value, p)
        if Self:isBuddy(p) then
            return "packages/ysch_Al/qml/ZixiBox"
        end
        return ""
    end,
}
local taoyin = fk.CreateActiveSkill{
    name = "ysch4_taoyin",
    interaction = function(self)
        local names ={}
        local used = Self:getTableMark("ysch4_taoyin-phase")
        if not table.contains(used,"shefu") then
            local mark = Self:getTableMark("@[ysch3__shefu]")
            local all_names = U.getAllCardNames("btd", true)
            table.insertTableIfNeed(names,table.filter(all_names, function(name)
                return table.every(mark, function(shefu_pair)
                    return shefu_pair[2] ~= name
                end)
            end))
        end
        if not table.contains(used,"premeditate") then
            table.insertIfNeed(names,"rfenghou__premeditate")
        end
        if #names == 0 then return end
        return U.CardNameBox {choices = names}
    end,
    can_use = function (self, player, card, extra_data)
        return #player:getTableMark("ysch4_taoyin-phase") < 2
    end,
    max_card_num = 1,
    card_filter = function (self, to_select, selected, player)
        return #selected == 0 and self.interaction.data
    end,
    target_num = 0,
    target_filter = Util.FalseFunc,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local cards = {}
        if #effect.cards > 0 then
            cards = effect.cards
        else
            cards = getShade(room, 1)
        end
        if #cards > 0 then
            local used = player:getTableMark("ysch4_taoyin-phase")
            if self.interaction.data == "rfenghou__premeditate" then
                table.insert(used,"premeditate")
                premeditate (player, cards[1], self.name, player.id)
            else
                table.insert(used,"shefu")
                player:addToPile("#shefu_ambush", cards, false, self.name)
                local mark = player:getTableMark("@[ysch3__shefu]")
                table.insert(mark, {cards[1], self.interaction.data})
                room:setPlayerMark(player, "@[ysch3__shefu]", mark)
            end
            room:setPlayerMark(player,"ysch4_taoyin-phase",used)
        end
    end,
}
local taoyin_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_taoyin_trigger",
    mute = true,
    events = {fk.CardUsing},
    can_trigger = function (self, event, target, player, data)
        return target ~= player and player.phase == Player.NotActive and
        table.find(player:getTableMark("@[ysch3__shefu]"), function (shefu_pair)
          return shefu_pair[2] == data.card.trueName
        end) and U.IsUsingHandcard(target, data)
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        if room:askForSkillInvoke(player, self.name, nil, "#ysch4_taoyin_trigger-invoke::"..target.id..":"..data.card:toLogString()) then
            room:doIndicate(player.id, {target.id})
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:notifySkillInvoked(player,"ysch4_taoyin","control")
        local mark = player:getTableMark("@[ysch3__shefu]")
        for i = 1, #mark, 1 do
            if mark[i][2] == data.card.trueName then
                local cid = mark[i][1]
                table.remove(mark, i)
                room:setPlayerMark(player, "@[ysch3__shefu]", #mark > 0 and mark or 0)
                if table.contains(player:getPile("#shefu_ambush"), cid) then
                    premeditate (player, cid, "ysch4_taoyin", player.id)
                    --room:moveCardTo(cid, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "ysch4_taoyin", nil, true, player.id)
                end
                break
            end
        end
        data.tos = {}
        room:sendLog{ type = "#CardNullifiedBySkill", from = target.id, arg = "ysch4_taoyin", arg2 = data.card:toLogString() }
    end,
}
taoyin:addRelatedSkill(taoyin_trigger)
simayi:addSkill(taoyin)
Fk:loadTranslationTable{
    ["ysch4_taoyin"] = "韬隐",
    [":ysch4_taoyin"] = "出牌阶段每项各限一次，你可以蓄谋/“设伏”一张牌或游戏外的一张【影】。该牌生效后，对之进行另一项操作。",
    ["#shefu_ambush"] = "伏兵",
    ["@[ysch3__shefu]"] = "伏兵",
    ["#ysch4_taoyin_trigger-invoke"] = "韬隐·设伏：可以令 %dest 使用的 %arg 无效",
    ["ysch4_yanfu"] = "焉服",
    [":ysch4_yanfu"] = "判定阶段开始时，你可以将判定区内的蓄谋或延时牌置为另一项，若如此做，每有一张蓄谋牌失效，每有一张延时牌生效，你便可摸两张牌或回复1点体力。",
}]]--
local wangling = General:new(extension, "ysch3__wangling", "wei", 3, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__wangling"] = "王凌",
    ["#ysch3__wangling"] = "缚爻浮瑶",
    ["designer:ysch3__wangling"] = "铝&yyuaN",
    ["cv:ysch3__wangling"] = "官方",
    ["illustrator:ysch3__wangling"] = "西国红云",
}
local xingqi = fk.CreateViewAsSkill{
    name = "ysch3_xingqi",
    expand_pile = function (self,player)
        return player:getCardIds("j")
    end,
    pattern = ".|.|.|.|.|basic",
    interaction = function()
        local all_names = getAllCardNames("b")
        local names = U.getViewAsCardNames(Self, "ysch3_xingqi", all_names)
        if #names > 0 then
          return U.CardNameBox { choices = names, all_choices = all_names }
        end
    end,
    card_filter = function(self, to_select, selected)
        return #selected == 0 and table.contains(Self:getCardIds("ej"),to_select)
    end,
    view_as = function (self, cards, player)
        if #cards ~= 1 or not self.interaction.data then return end
        local card = Fk:cloneCard(self.interaction.data)
        card:addSubcard(cards[1])
        card.skillName = self.name
        return card
    end,
    enabled_at_play = function (self, player)
        return #player:getCardIds("ej")>0
    end,
    enabled_at_response = function (self, player)
        return #player:getCardIds("ej")>0
    end,
    before_use = function (self, player, use)
        local room = player.room
        local card = use.card
        if card.color ~= Fk:getCardById(room.draw_pile[1]).color then
            room:moveCardTo(use.card, Card.DiscardPile, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
            player:drawCards(1,self.name)
            return ""
        end
    end,
    attached_skill_name = "&ysch3_xingqi_global",
}
local xingqi_global = fk.CreateViewAsSkill{
    name = "&ysch3_xingqi_global",
    expand_pile = function (self,player)
        return player:getCardIds("j")
    end,
    pattern = ".|.|.|.|.|basic",
    interaction = function()
        local all_names = getAllCardNames("b")
        local names = U.getViewAsCardNames(Self, "&ysch3_xingqi_global", all_names)
        if #names > 0 then
          return U.CardNameBox { choices = names, all_choices = all_names }
        end
    end,
    card_filter = function(self, to_select, selected)
        return #selected == 0 and table.contains(Self:getCardIds("ej"),to_select)
    end,
    view_as = function (self, cards, player)
        if #cards ~= 1 or not self.interaction.data then return end
        local card = Fk:cloneCard(self.interaction.data)
        card:addSubcard(cards[1])
        card.skillName = self.name
        return card
    end,
    enabled_at_play = function (self, player)
        return #player:getCardIds("ej") > 0 and not player:hasSkill(xingqi)
    end,
    enabled_at_response = function (self, player)
        return #player:getCardIds("ej") > 0 and not player:hasSkill(xingqi)
    end,
    before_use = function (self, player, use)
        local room = player.room
        local card = use.card
        local currents = table.filter(room:getAllPlayers(),function (cp)
            return cp:hasSkill(xingqi)
        end)
        if card.color ~= Fk:getCardById(room.draw_pile[1]).color and #currents > 0 then
            room:moveCardTo(use.card, Card.DiscardPile, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
            currents[1]:drawCards(1,self.name)
            return ""
        end
    end,
}
local xingqi_trigger = fk.CreateTriggerSkill{
    name = "#ysch3_xingqi_trigger",
    mute = true,
  
    refresh_events = {fk.AfterCardsMove, fk.AfterDrawPileShuffle, fk.EventAcquireSkill, fk.EventLoseSkill, fk.EventPhaseStart, fk.EventPhaseEnd},
    can_refresh = function(self, event, target, player, data)
        if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
            return data == xingqi
        else
            return player:hasSkill(xingqi) and ((target == player and player.phase == Player.Play) or not table.contains({fk.EventPhaseStart, fk.EventPhaseEnd},event))
        end
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        local function getNumberStr(num)
            if num == 1 then
              return "A"
            elseif num == 11 then
              return "J"
            elseif num == 12 then
              return "Q"
            elseif num == 13 then
              return "K"
            elseif num == 0 then
              return "X"
            end
            return tostring(num)
        end
        if event == fk.AfterCardsMove or event == fk.AfterDrawPileShuffle then
            local draw_pile = room.draw_pile
            if player:hasSkill(xingqi) and player.phase ~= Player.Play then
                local card = Fk:getCardById(draw_pile[1])
                local ret = Fk:translate(card.name)
                if #ret > 9 then
                    ret = string.sub(ret, 1, 6)
                end
                ret = ret .. Fk:translate("log_" .. card:getSuitString())
                if card.color == Card.Red then
                    ret = ret .. "<font color=#CC3131>".. getNumberStr(card.number) .."</font>"
                else
                    ret = ret .. getNumberStr(card.number)
                end
                U.setPrivateMark(player, "ysch3_xingqi", {ret})
            else
                room:setPlayerMark(player, "@[private]ysch3_xingqi", 0)
            end
        elseif event == fk.EventAcquireSkill or event == fk.EventPhaseEnd then
            local draw_pile = room.draw_pile
            if player:hasSkill(xingqi) then
                local card = Fk:getCardById(draw_pile[1])
                local ret = Fk:translate(card.name)
                if #ret > 9 then
                    ret = string.sub(ret, 1, 6)
                end
                ret = ret .. Fk:translate("log_" .. card:getSuitString())
                if card.color == Card.Red then
                    ret = ret .. "<font color=#CC3131>".. getNumberStr(card.number) .."</font>"
                else
                    ret = ret .. getNumberStr(card.number)
                end
                U.setPrivateMark(player, "ysch3_xingqi", {ret})
            end
        elseif event == fk.EventLoseSkill or event == fk.EventPhaseStart then
            room:setPlayerMark(player, "@[private]ysch3_xingqi", 0)
        end
    end,
}
xingqi:addRelatedSkill(xingqi_trigger)
Fk:addSkill(xingqi_global)
wangling:addSkill(xingqi)
local mibei_foresightSkill = fk.CreateActiveSkill{
    name = "ysch3_mibei_foresight_skill",
    mod_target_filter = Util.TrueFunc,
    can_use = function(self, player, card)
        return Util.SelfCanUse(self, player, card)
    end,
    on_use = function(self, room, cardUseEvent)
        if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
        cardUseEvent.tos = {{cardUseEvent.from}}
        end
    end,
    on_effect = function(self, room, effect)
        local to = room:getPlayerById(effect.to)
        local cards = room:askForCard(to, 2, 2, false, self.name, false, ".", "#ysch3_mibei-choose")
        if #cards > 0 then
            room:moveCardTo(cards, Card.DrawPile, nil, fk.ReasonPut, self.name, nil, false)
            room:askForGuanxing(to, cards, nil, nil)
        end
        room:drawCards(to, 2, self.name)
    end
}
mibei_foresightSkill.cardSkill = true
Fk:addSkill(mibei_foresightSkill)
local mibei = fk.CreateTriggerSkill{
    name = "ysch3_mibei",
    events = {fk.EventPhaseStart},
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Start and player:getHandcardNum() >= 2 and
        not table.every(player.room.alive_players, function(p) return player:getHandcardNum() >= p:getHandcardNum() end)
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:useVirtualCard("ysch_Al__foresight", nil, player, {player}, self.name)
    end,

    refresh_events = {fk.PreCardEffect},
    can_refresh = function(self, event, target, player, data)
        return data.from == player.id and data.card.trueName == "foresight" and table.contains(data.card.skillNames, self.name)
    end,
    on_refresh = function(self, event, target, player, data)
        local card = data.card:clone()
        local c = table.simpleClone(data.card)
        for k, v in pairs(c) do
            card[k] = v
        end
        card.skill = mibei_foresightSkill
        data.card = card
    end,
}
wangling:addSkill(mibei)
local zifu = fk.CreateActiveSkill{
    name = "ysch3_zifu",
    anim_type = "drawcard",
    card_num = 0,
    target_num = 0,
    prompt = "#steam__jishe",
    can_use = function(self, player)
        return player:hasSkill(self) and player:getMaxCards() > 0
    end,
    card_filter = Util.FalseFunc,
    interaction = function(self)
        return UI.ComboBox {choices = {"Top", "Bottom"}}
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local choice = self.interaction.data
        local card = room:getNCards(1, choice == "Top" and "top" or "bottom")[1]
        premeditate (player, card, self.name, player.id)
        if player.dead then return end
        room:addPlayerMark(player, MarkEnum.MinusMaxCardsInTurn, 1)
    end,
}
wangling:addSkill(zifu)
Fk:loadTranslationTable{
    ["ysch3_xingqi"] = "星启",
    [":ysch3_xingqi"] = "出牌阶段外牌堆顶的牌对你可见。所有角色可以将各自场上一张牌当任意基本牌使用，若与牌堆顶牌颜色不同，你摸一张牌令之无效。",
    ["&ysch3_xingqi_global"] = "星启",
    [":&ysch3_xingqi_global"] = "你可以将自己场上一张牌当任意基本牌使用。",
    ["@[private]ysch3_xingqi"] = "星启",
    ["ysch3_mibei"] = "秘备",
    [":ysch3_mibei"] = "准备阶段，若你的手牌不为全场最多，你可视为使用<a href='ysch3_mibei-adaptation'>卜算两张手牌的【洞烛先机】</a>。",
    ["ysch3_mibei-adaptation"] = "其实就是卜算两张手牌再摸两张牌。<br><b>卜算两张手牌</b>：将两张手牌任意置于牌堆两端",
    ["#ysch3_mibei-choose"] = "秘备：选择要卜算的两张手牌",
    ["ysch3_zifu"] = "自缚",
    [":ysch3_zifu"] = "出牌阶段，你可以令本回合手牌上限-1并蓄谋牌堆一端的牌。",

    ["$ysch3_xingqi1"] = "先谋后事者昌，先事后谋者亡！",
    ["$ysch3_xingqi2"] = "司马氏虽权尊势重，吾等徐图亦无不可！",
    ["$ysch3_mibei1"] = "密为之备，不可有失。",
    ["$ysch3_mibei2"] = "事以密成，语以泄败！",
    ["$ysch3_zifu1"] = "澄汰王室，迎立宗子！",
    ["$ysch3_zifu2"] = "僣孽为害，吾岂可谋而不行？",
}
local yujig = General:new(extension, "ysch3__yujig", "chu", 3, 3, General.Female)--
Fk:loadTranslationTable{
    ["chu"] = "楚",
    ["ysch3__yujig"] = "虞姬",
    ["#ysch3__yujig"] = "素心不染",
    ["designer:ysch3__yujig"] = "铝",
    ["cv:ysch3__yujig"] = "未知",
    ["illustrator:ysch3__yujig"] = "英雄杀",
}
local wulanshan = fk.CreateTriggerSkill{
    name = "ysch3_wulanshan",
    switch_skill_name = "ysch3_wulanshan",
    anim_type = "defensive",
    mute = true,
    events = {fk.AfterCardsMove},
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) and not player:isAllNude() then
            for _, move in ipairs(data) do
                if move.from == player.id and move.moveReason ~= fk.ReasonUse and move.moveReason ~= fk.ReasonResonpse then
                    for _, info in ipairs(move.moveInfo) do
                        if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
                        Fk:getCardById(info.cardId).color == Card.Black then
                            return true
                        end
                    end
                end
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local prompt = "#ysch3_wulanshan-prompt:::"
        if player:getSwitchSkillState(self.name, true) ~= fk.SwitchYang then
            prompt = prompt.."analeptic"
        else
            prompt = prompt.."slash"
        end
        local ids = room:askForCard(player, 1, 1, true, self.name, true, ".", prompt,player:getCardIds("j"))
        if #ids > 0 then
            self.cost_data = ids
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:notifySkillInvoked(player,self.name,"defensive")
        if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
            player:broadcastSkillInvoke(self.name,2)
            room:setCardMark(Fk:getCardById(self.cost_data[1]),"@@ysch3_wulanshan_sha-inhand",0)
            room:setCardMark(Fk:getCardById(self.cost_data[1]),"@@ysch3_wulanshan_jiu-inhand",1)
        else
            player:broadcastSkillInvoke(self.name,1)
            room:setCardMark(Fk:getCardById(self.cost_data[1]),"@@ysch3_wulanshan_jiu-inhand",0)
            room:setCardMark(Fk:getCardById(self.cost_data[1]),"@@ysch3_wulanshan_sha-inhand",1)
        end
        player:showCards(self.cost_data)
        if not table.contains(player:getCardIds("h"),self.cost_data[1]) then
            room:addTableMarkIfNeed(player, "ysch3_wulanshan_cards-phase", self.cost_data[1])
            if table.contains(player:getCardIds("j"),self.cost_data[1]) then
                room:moveCardTo(self.cost_data[1], Card.Processing, player, fk.ReasonJustMove, nil, nil, false, nil)
            end
            premeditate (player, self.cost_data[1], self.name, player.id)
        end
    end,

    refresh_events = {fk.EventPhaseEnd},
    can_refresh = function (self, event, target, player, data)
        return #player:getTableMark("ysch3_wulanshan_cards-phase") > 0
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local cards = player:getTableMark("ysch3_wulanshan_cards-phase")
        for _, id in ipairs(cards) do
            local use = U.askForUseRealCard(room, player, {id}, ".", self.name,
            "#ysch3_wulanshan-use:::"..Fk:getCardById(id):toLogString(),
            {expand_pile = {id}, extra_use = true}, true, true)
            if use then
                room:useCard(use)
            else
                if room:askForSkillInvoke(player,self.name,nil,"#ysch3_wulanshan-gain:::"..Fk:getCardById(id,true):toLogString()) then
                    room:obtainCard(player, id, true, fk.ReasonPrey, player.id, self.name)
                end
            end
        end
    end,
}
local wulanshan_filter = fk.CreateFilterSkill{
    name = "#ysch3_wulanshan-filter",
    frequency = Skill.Compulsory,
    card_filter = function(self, card, player, isJudgeEvent)
        return player:hasSkill(wulanshan.name) and (card:getMark("@@ysch3_wulanshan_sha-inhand") > 0 or card:getMark("@@ysch3_wulanshan_jiu-inhand") > 0 ) and
        table.contains(player:getCardIds("hj"), card.id)
    end,
    view_as = function(self, to_select)
        if to_select:getMark("@@ysch3_wulanshan_sha-inhand") > 0 then
            return Fk:cloneCard("slash", to_select.suit, to_select.number)
        else
            return Fk:cloneCard("analeptic", to_select.suit, to_select.number)
        end
    end,
}
wulanshan:addRelatedSkill(wulanshan_filter)
yujig:addSkill(wulanshan)
---韵律技转韵
---@param room Room
---@param player ServerPlayer
---@param skillName string
---@param scope? integer
local function changeRhyme(room, player, skillName, scope)
    scope = scope or Player.HistoryPhase
    room:setPlayerMark(player, MarkEnum.SwithSkillPreName .. skillName, player:getSwitchSkillState(skillName, true))
    room:notifySkillInvoked(player, skillName, "switch")
    player:setSkillUseHistory(skillName, 0, scope)
end
local yiqiyang = fk.CreateActiveSkill{
    name = "ysch3_yiqiyang",
    anim_type = "support",
    card_num = 0,
    card_filter = Util.FalseFunc,
    target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
        if self.interaction.data ~= "#ysch3_yiqiyang1" then
            local card = Fk:cloneCard("ysch_Al__underhanding")
            card.skillName = self.name
            return card.skill:targetFilter(to_select, {}, {}, card, {bypass_distances = true}, player) and
            to_select ~= player.id and not Fk:currentRoom():getPlayerById(to_select):isAllNude() and #selected < 2
        else
            return false
        end
    end,
    min_target_num = 0,
    max_target_num = 2,
    feasible = function (self, selected, selected_cards, player)
        if self.interaction.data ~= "#ysch3_yiqiyang1" then
            return #selected > 0
        else
            return true
        end
    end,
    prompt = function(self)
        if Self:getSwitchSkillState(self.name, false) == fk.SwitchYang then
            return "#"..self.name.."-level"
        else
            return "#"..self.name.."-oblique"
        end
    end,
    interaction = function(self)
        if Self:getSwitchSkillState(self.name, false) == fk.SwitchYang then
            return UI.ComboBox {choices = {"#ysch3_yiqiyang1","#ysch3_yiqiyang3"}}
        else
            return UI.ComboBox {choices = {"#ysch3_yiqiyang2","#ysch3_yiqiyang3"}}
        end
    end,
    can_use = function (self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1
    end,
    --[[times = function(self)
        return Self.phase == Player.Play and 2 - Self:usedSkillTimes(self.name, Player.HistoryPhase) or -1
    end,]]--
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        room:setPlayerMark(player,"ysch3_yiqiyang_change-phase",1)
        if table.contains({"#ysch3_yiqiyang1","#ysch3_yiqiyang3"},self.interaction.data) then
            for _, id in ipairs(player:getCardIds("h")) do
                local hc = Fk:getCardById(id)
                if hc.color == Card.Red then
                    room:setPlayerMark(player,"ysch3_yiqiyang_change-phase",0)
                    break
                end
            end
            U.swapCardsWithPile(player, player:getCardIds("h"), room:getNCards(4), self.name, "Top")
            if player:getMark("ysch3_yiqiyang_change-phase") == 1 then
                for _, id in ipairs(player:getCardIds("h")) do
                    local hc = Fk:getCardById(id)
                    if hc.color == Card.Red then
                        room:setPlayerMark(player,"ysch3_yiqiyang_change-phase",0)
                        break
                    end
                end
            end
        end
        if table.contains({"#ysch3_yiqiyang2","#ysch3_yiqiyang3"},self.interaction.data) then
            local card = Fk:cloneCard("ysch_Al__underhanding")
            card.skillName = self.name
            room:useCard{
                from = player.id,
                tos = table.map(effect.tos, function(id) return {id} end),
                card = card,
                extra_data = {
                    ysch3_yiqiyang = true,
                }
            }
        end
        if player:getMark("ysch3_yiqiyang_change-phase") == 1 then
            room:setPlayerMark(player,"ysch3_yiqiyang_change-phase",0)
            if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
                room:setPlayerMark(player,"@ysch3_yiqiyang","平")
            else
                room:setPlayerMark(player,"@ysch3_yiqiyang","仄")
            end
            changeRhyme(room, player, "ysch3_yiqiyang")
        end
        if self.interaction.data == "#ysch3_yiqiyang3" then
            room:endTurn()
        end
    end,
    on_acquire = function (self, player, is_start)
        local room = player.room
        if player:getSwitchSkillState(self.name, false) == fk.SwitchYang then
            room:setPlayerMark(player,"@ysch3_yiqiyang","平")
        else
            room:setPlayerMark(player,"@ysch3_yiqiyang","仄")
        end
    end,
    on_lose = function (self, player, is_death)
        player.room:setPlayerMark(player, "@ysch3_yiqiyang", 0)
    end,
}
local yiqiyang_trigger = fk.CreateTriggerSkill{
    name = "#ysch3_yiqiyang-trigger",

    refresh_events = {fk.GameStart,fk.CardUseFinished},
    can_refresh = function (self, event, target, player, data)
        return player:hasSkill(yiqiyang.name) and ( (data and data.extra_data and data.extra_data.ysch3_yiqiyang and player:getMark("ysch3_yiqiyang_change-phase") == 1) or event ~= fk.CardUseFinished )
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        if event == fk.GameStart then
            if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
                room:setPlayerMark(player,"@ysch3_yiqiyang","平")
            else
                room:setPlayerMark(player,"@ysch3_yiqiyang","仄")
            end
            changeRhyme(room, player, "ysch3_yiqiyang")
        else
            if data.extra_data.underhanding_gain then
                for _, id in ipairs(data.extra_data.underhanding_gain) do
                    local hc = Fk:getCardById(id)
                    if hc.color == Card.Red then
                        room:setPlayerMark(player,"ysch3_yiqiyang_change-phase",0)
                        break
                    end
                end
            end
            if player:getMark("ysch3_yiqiyang_change-phase") == 1 and data.extra_data.underhanding_lose then
                for _, id in ipairs(data.extra_data.underhanding_lose) do
                    local hc = Fk:getCardById(id)
                    if hc.color == Card.Red then
                        room:setPlayerMark(player,"ysch3_yiqiyang_change-phase",0)
                        break
                    end
                end
            end
        end
    end,
}
yiqiyang:addRelatedSkill(yiqiyang_trigger)
yujig:addSkill(yiqiyang)
Fk:loadTranslationTable{
    ["ysch3_wulanshan"] = "舞阑珊",
    [":ysch3_wulanshan"] = "转换技，你不因使用或打出而失去黑色牌时，可展示区域内一张牌视为①【酒】②【杀】，若不为手牌，蓄谋之并可于此阶段结束时使用或收回。",
    ["#ysch3_wulanshan-prompt"] = "是否发动 舞阑珊，展示区域内一张牌视为【%arg】",
    ["#ysch3_wulanshan-use"] = "舞阑珊：你可以使用此%arg，或点“取消”选择是否收回此牌",
    ["#ysch3_wulanshan-gain"] = "舞阑珊：是否收回%arg",
    ["#ysch3_wulanshan-filter"] = "舞阑珊",
    ["@@ysch3_wulanshan_sha-inhand"] = "舞阑珊",
    ["@@ysch3_wulanshan_jiu-inhand"] = "舞阑珊",
    ["ysch3_yiqiyang"] = "意气扬",
    ["rhyme_skill"] = "<b>韵律技：</b><br>一种特殊的技能，分为“平”和“仄”两种状态。游戏开始时，韵律技处于“平”状态；满足“转韵”条件后，"..
    "韵律技会转换到另一个状态，且重置技能发动次数。",
    [":ysch3_yiqiyang"] = "<a href='rhyme_skill'>韵律技</a>，出牌阶段限一次，你可①用手牌交换牌堆顶的四张牌②视为使用【瞒天过海】。"..
    "<br>背水：结算后，结束此回合。"..
    "<br>转韵：游戏开始时或本次仅有黑色牌移动。",
    ["@ysch3_yiqiyang"] = "意气扬",
    ["#ysch3_yiqiyang-level"] = "意气扬：你可用手牌交换牌堆顶的四张牌",
    ["#ysch3_yiqiyang-oblique"] = "意气扬：你可视为使用【瞒天过海】",
    ["#ysch3_yiqiyang1"] = "用手牌交换牌堆顶的四张牌",
    ["#ysch3_yiqiyang2"] = "视为使用【瞒天过海】",
    ["#ysch3_yiqiyang3"] = "背水：结算后，结束此回合",

    ["$ysch3_wulanshan1"] = "妾虽女儿身，愿化烈焰，护霸王。",
    ["$ysch3_wulanshan2"] = "劝君饮酒听虞歌，把盏回眸初相识。",
    ["$ysch3_yiqiyang1"] = "泪洒君袍，残躯何惜，惟愿王无羕。",
    ["$ysch3_yiqiyang2"] = "四面皆楚歌，与王共生死。",
}
local zhenji = General:new(extension, "ysch3__zhenji", "wei", 3, 3, General.Female)--
Fk:loadTranslationTable{
    ["ysch3__zhenji"] = "甄姬",
    ["#ysch3__zhenji"] = "洛水仙子",
    ["designer:ysch3__zhenji"] = "铝",
    ["cv:ysch3__zhenji"] = "官方",
    ["illustrator:ysch3__zhenji"] = "木美人",
}
local luoshen = fk.CreateTriggerSkill{
    name = "ysch3_luoshen",
    anim_type = "drawcard",
    events = {fk.TurnEnd},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and target:getNextAlive() == player
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local lastColor = nil
        while true do
            local judge = {
              who = player,
              reason = self.name,
              pattern = ".",
            }
            if lastColor ~= nil then
                local cid = table.find(room.draw_pile, function (id) return Fk:getCardById(id).color == lastColor and math.random()>0.5 end)
                if cid and math.random()>=0.5 then
                    table.removeOne(room.draw_pile, cid)
                    table.insert(room.draw_pile, 1, cid)
                    room:syncDrawPile()
                end
                if lastColor == Card.Black then
                    judge.pattern = ".|.|spade,club"
                else
                    judge.pattern = ".|.|heart,diamond"
                end
            end
            room:judge(judge)
            room:obtainCard(player,judge.card,true,nil,player.id,self.name)
            if (lastColor ~= nil and judge.card.color ~= lastColor) or player.dead then
                if not player.dead then
                    player:turnOver()
                end
                break
            elseif not room:askForSkillInvoke(player, self.name) then
                break
            end
            lastColor = judge.card.color
        end
    end,
}
zhenji:addSkill(luoshen)
local lingbo = fk.CreateTriggerSkill{
    name = "ysch3_lingbo",
    anim_type = "offensive",
    events = {fk.BeforeTurnOver,fk.DamageInflicted},
    prompt = "#ysch3_lingbo-prompt",
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and target == player and (event ~= fk.BeforeTurnOver or target.faceup)
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:loseHp(player, 1, self.name)
        U.askForUseVirtualCard(room,player,"ysch_Al__bogus_flower",nil,self.name,"#ysch3_lingbo-flower")
        return true
    end,
}
zhenji:addSkill(lingbo)
Fk:loadTranslationTable{
    ["ysch3_luoshen"] = "洛神",
    [":ysch3_luoshen"] = "你上家的回合结束时，你可进行一次获得判定牌的判定。若结果与本流程上次不同，你翻面；否则你可以重复此流程。",
    ["ysch3_lingbo"] = "凌波",
    [":ysch3_lingbo"] = "你即将受到伤害或翻至背面时，可改为失去1点体力，然后你可以视为使用一张【树上开花】。",
    ["#ysch3_lingbo-prompt"] = "是否发动 凌波，改为失去1点体力",
    ["#ysch3_lingbo-flower"] = "凌波：你可以视为使用一张【树上开花】",

    ["$ysch3_luoshen1"] = "髣髴兮若轻云之蔽月。",
    ["$ysch3_luoshen2"] = "飘飖兮若流风之回雪。",
    ["$ysch3_lingbo1"] = "凌波微步，罗袜生尘。",
    ["$ysch3_lingbo2"] = "体迅飞凫，飘忽若神。",
}
local xujing = General:new(extension, "ysch3__xujing", "shu", 3, 3, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__xujing"] = "许靖",
    ["#ysch3__xujing"] = "璞玉有瑕",
    ["designer:ysch3__xujing"] = "铝",
    ["cv:ysch3__xujing"] = "官方",
    ["illustrator:ysch3__xujing"] = "匪萌十月",
}
local yuxu = fk.CreateTriggerSkill{
    name = "ysch3_yuxu",
    frequency = Skill.Compulsory,
    events = {fk.PreCardEffect,fk.CardUsing},
    mute = true,
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) and target == player then
            if event == fk.CardUsing then
                return (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) and (not data.card:isVirtual() or #data.card.subcards > 0)
            else
                return data.card:isVirtual() and #data.card.subcards == 0
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        if event == fk.CardUsing then
            local ids = {data.card.id}
            if #data.card.subcards > 0 then
                ids = data.card.subcards
            end
            if #ids > 1 then
                local dis = room:askForCardsChosen(player,player,1,1,{ card_data = { { "底牌", ids } } },self.name,"#ysch3_yuxu-prompt")
                if #dis > 0 then
                    self.cost_data = dis
                    return true
                end
            else
                self.cost_data = ids
                return true
            end
        else
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if event == fk.CardUsing then
            local _card = Fk:cloneCard(data.card.name)
            if #data.card.subcards > 0 then
                p(data.card.subcards)
                table.removeOne(data.card.subcards,self.cost_data[1])
                p(data.card.subcards)
                _card:addSubcards(data.card.subcards)
            end
            room:moveCards({
                from = player.id,
                ids = self.cost_data,
                toArea = Card.DiscardPile,
                moveReason = fk.ReasonPutIntoDiscardPile,
                skillName = self.name,
            })
            room:sendLog{
                type = "#FilterCard",
                from = player.id,
                arg = self.name,
                arg2 = data.card:toLogString(),
                arg3 = _card:toLogString(),
            }
            data.card = _card
            player:drawCards(1,self.name)
        else
            return true
        end
    end,
}
xujing:addSkill(yuxu)
Fk:addQmlMark{
    name = "ysch3_shijian",
    how_to_show = function(_, value)
        if type(value) ~= "table" then return " " end
        if type(value.suits) ~= "table" or #value.suits == 0 then return " " end
        return table.concat(table.map(value.suits, function(suit)
            return Fk:translate(Card.getSuitString({ suit = suit }, true))
        end), "")
    end,
    qml_path = "packages/utility/qml/ViewPile"
}
local shijian = fk.CreateViewAsSkill{
    name = "ysch3_shijian",
    pattern = ".",
    interaction = function()
        local names, all_names = {}, {}
        local mark = Self:getMark("@[ysch3_shijian]")
        if type(mark) ~= "table" then
            mark = {
                value = {},
                suits = {},
            }
        end
        for _, id in ipairs(Fk:getAllCardIds()) do
            local card = Fk:getCardById(id)
            if (card.type == Card.TypeBasic or card:isCommonTrick()) and not card.is_derived and table.find(Self:getCardIds("he"), function(pid) return Fk:getCardById(pid).name == card.name end) 
            and not table.contains(mark.value,card.name) then
                table.insertIfNeed(all_names, card.name)
                local to_use = Fk:cloneCard(card.name)
                if ((Fk.currentResponsePattern == nil and Self:canUse(to_use) and not Self:prohibitUse(to_use)) or
                    (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use))) then
                    table.insertIfNeed(names, card.name)
                end
            end
        end
        if #names == 0 then return false end
        return U.CardNameBox { choices = names, all_choices = all_names }
    end,
    card_num = 2,
    card_filter = function(self, to_select, selected)
        if #selected == 2 then return false end
        local mark = Self:getMark("@[ysch3_shijian]")
        if type(mark) ~= "table" then
            mark = {
                value = {},
                suits = {},
            }
        end
        return not table.contains(mark.suits, Fk:getCardById(to_select).suit)
    end,
    handly_pile = true,
    view_as = function (self, cards, player)
        if #cards < 2 or not self.interaction.data then return end
        local card = Fk:cloneCard(self.interaction.data)
        card:addSubcards(cards)
        card.skillName = self.name
        return card
    end,
    before_use = function (self, player, use)
        local room = player.room
        local shows = {}
        for _, pid in ipairs(player:getCardIds("he")) do
            if Fk:getCardById(pid).name == use.card.name then
                table.insert(shows,pid)
            end
        end
        local show = shows
        if #shows > 1 then
            show = room:askForCard(player, 1, 1, true, self.name, false, use.card.name, "ysch3_shijian-show")
        end
        player:showCards(show)

        local mark = player:getMark("@[ysch3_shijian]")
        if type(mark) ~= "table" then
            mark = {
                value = {},
                suits = {},
            }
        end
        local cards = use.card.subcards
        for _, cid in ipairs(cards) do
            local suit = Fk:getCardById(cid):getSuitString(true)
            if suit ~= "log_nosuit" then table.insertIfNeed(mark.suits, Fk:getCardById(cid).suit) end
        end
        table.insertIfNeed(mark.value, use.card.name)
        room:setPlayerMark(player, "@[ysch3_shijian]", mark)
    end,
    enabled_at_play = function (self, player)
        local mark = Self:getMark("@[ysch3_shijian]")
        if type(mark) ~= "table" then
            mark = {
                value = {},
                suits = {},
            }
        end
        for _, id in ipairs(Fk:getAllCardIds()) do
            local card = Fk:getCardById(id)
            if (card.type == Card.TypeBasic or card:isCommonTrick()) and not card.is_derived and table.find(Self:getCardIds("he"), function(pid) return Fk:getCardById(pid).name == card.name end)
            and not table.contains(mark.value,card.name) then
                local to_use = Fk:cloneCard(card.name)
                if ((Fk.currentResponsePattern == nil and Self:canUse(to_use) and not Self:prohibitUse(to_use)) or
                    (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use))) then
                    return true
                end
            end
        end
    end,
    enabled_at_response = function (self, player, response)
        if response then return false end
        local mark = Self:getMark("@[ysch3_shijian]")
        if type(mark) ~= "table" then
            mark = {
                value = {},
                suits = {},
            }
        end
        for _, id in ipairs(Fk:getAllCardIds()) do
            local card = Fk:getCardById(id)
            if (card.type == Card.TypeBasic or card:isCommonTrick()) and not card.is_derived and table.find(Self:getCardIds("he"), function(pid) return Fk:getCardById(pid).name == card.name end)
            and not table.contains(mark.value,card.name) then
                local to_use = Fk:cloneCard(card.name)
                if ((Fk.currentResponsePattern == nil and Self:canUse(to_use) and not Self:prohibitUse(to_use)) or
                    (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use))) then
                    return true
                end
            end
        end
    end,
}
local shijian_trigger = fk.CreateTriggerSkill{
    name = "#ysch3_shijian_trigger",
    main_skill = shijian,
  
    refresh_events = {fk.AfterTurnEnd,fk.AfterRoundEnd},
    can_refresh = function(self, event, target, player, data)
      local mark = player:getMark("@[ysch3_shijian]")
      return type(mark) == "table" and ((#mark.suits > 0 and event == fk.AfterTurnEnd) or (#mark.value > 0 and event == fk.AfterRoundEnd))
    end,
    on_refresh = function(self, event, target, player, data)
        local mark = player:getMark("@[ysch3_shijian]")
        if event == fk.AfterTurnEnd then
            mark.suits = {}
        else
            mark = 0
        end
        player.room:setPlayerMark(player, "@[ysch3_shijian]", mark)
    end,
}
shijian:addRelatedSkill(shijian_trigger)
xujing:addSkill(shijian)
Fk:loadTranslationTable{
    ["ysch3_yuxu"] = "誉虚",
    [":ysch3_yuxu"] = "锁定技，你使用即时牌时，移去其一张底牌并摸一张牌。你使用无实体牌生效前，无效之。",
    ["#ysch3_yuxu-prompt"] = "誉虚：移去其中一张底牌",
    ["#ysch3_yuxu-log"] = "%from 发动了〖%arg〗，移去了 %arg2 的底牌 %arg3",
    ["ysch3_shijian"] = "实荐",
    [":ysch3_shijian"] = "每回合每种花色、每轮每种牌名各限一次，你可以展示一张即时牌，并将两张牌当之使用。",
    ["ysch3_shijian-show"] = "实荐：展示一张所需使用的即时牌",
    ["@[ysch3_shijian]"] = "实荐",

    ["$ysch3_yuxu1"] = "君子撷翠屏，盈锦绣大道，颂万世太平。",
    ["$ysch3_yuxu2"] = "野陌有丹桂，沐金秋银露，梦白鹿青崖。",
    ["$ysch3_shijian1"] = "四时钟灵，金秋独贵，品丹桂而闻雨露秋风。",
    ["$ysch3_shijian2"] = "晚木潇潇，雁归衡阳，一叶落而天下知秋。",
}
local puyuan = General:new(extension, "ysch3__puyuan", "shu", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__puyuan"] = "蒲元",
    ["#ysch3__puyuan"] = "淬炼百兵",
    ["designer:ysch3__puyuan"] = "铝<br>鸣谢：yyuaN",
    ["cv:ysch3__puyuan"] = "官方",
    ["illustrator:ysch3__puyuan"] = "zoo",
}
Fk:addQmlMark{
    name = "curse",
    how_to_show = function(name, value)
        if type(value) == "table" then
            local curses = {}
            for _, str in ipairs(value) do
                if str:startsWith("@@ysch3_shengong") then
                    table.insert(curses,str)
                end
            end
            return tostring(#curses)
        else
            return " "
        end
    end,
    qml_path = "packages/utility/qml/DetailBox"
}
local shengong = fk.CreateActiveSkill{
    name = "ysch3_shengong",
    mute = true,
    prompt = "#ysch3_shengong-prompt",
    card_num = 1,
    target_num = 0,
    target_filter = Util.FalseFunc,
    card_filter = function(self, to_select)
        return not Self:prohibitDiscard(Fk:getCardById(to_select))
    end,
    times = function(self)
        return Self.phase == Player.Play and 3 - Self:usedSkillTimes(self.name, Player.HistoryPhase) or -1
    end,
    can_use = function (self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) < 3
    end,
    on_use = function (self, room, effect)
        local from = room:getPlayerById(effect.from)
        room:notifySkillInvoked(from,self.name,"special")
        from:broadcastSkillInvoke(self.name,table.random({1,2}))
        room:throwCard(effect.cards, self.name, from, from)
        if from:isAlive() then
            local equips = table.filter(from:getCardIds("he"),function (id)
                local card = Fk:getCardById(id)
                if card.type == Card.TypeEquip then
                    local mark = {}
                    local max = 3
                    if card:getMark("@@ysch3_shengongC6") == 1 then
                        max = 5
                    end
                    for k, v in pairs(card.mark) do
                        if k and k:startsWith("@@ysch3_shengong") and v and v ~= 0 then
                            table.insert(mark, k)
                            if #mark >= max then
                                break
                            end
                        end
                    end
                    return #mark < max
                end
            end)
            if #equips == 0 then return end
            local equip = room:askForCard(from,1,1,true,self.name,false,tostring(Exppattern{ id = equips }))
            from:showCards(equip)
            local curse = {}
            local sub_type = Fk:getCardById(equip[1]).sub_type
            if sub_type == Card.SubtypeWeapon then
                curse = {"@ysch3_shengongA1","@ysch3_shengongA2","@ysch3_shengongA3","@ysch3_shengongA4","@ysch3_shengongA5",
                "@ysch3_shengongC1","@ysch3_shengongC2","@ysch3_shengongC3","@ysch3_shengongC4","@ysch3_shengongC5","@ysch3_shengongC6"}
                if string.find(Fk:translate(Fk:getCardById(equip[1]).name, "zh_CN"), "弓") ~= nil and 
                Fk:getCardById(equip[1]):getMark("@@ysch3_shengongC6") == 0 then
                    table.insert(curse,"@ysch3_shengongD1")
                end
            elseif sub_type == Card.SubtypeArmor then
                curse = {"@ysch3_shengongB1","@ysch3_shengongB2","@ysch3_shengongB3","@ysch3_shengongB4",
                "@ysch3_shengongC2","@ysch3_shengongC3","@ysch3_shengongC4","@ysch3_shengongC6"}
            elseif table.contains({Card.SubtypeOffensiveRide,Card.SubtypeDefensiveRide},sub_type) then
                curse = {"@ysch3_shengongB2","@ysch3_shengongD2",
                "@ysch3_shengongC2","@ysch3_shengongC3","@ysch3_shengongC4","@ysch3_shengongC6"}
            else
                curse = {"@ysch3_shengongC1","@ysch3_shengongC2","@ysch3_shengongC3","@ysch3_shengongC4","@ysch3_shengongC6"}
            end
            for _, str in ipairs(curse) do
                if Fk:getCardById(equip[1]):getMark("@"..str) == 1  or 
                (str == "@ysch3_shengongC6" and Fk:getCardById(equip[1]):getMark("@ysch3_shengongD1") == 1) then
                    table.removeOne(curse,str)
                end
            end
            if #curse > 0 then
                local choice = room:askForChoice(from,table.random(curse,3),self.name,"#ysch3_shengong-curse",true)
                --local choice = room:askForChoice(from,curse,self.name,"#ysch3_shengong-curse",true)
                if choice ~= "Cancel" then
                    room:setCardMark(Fk:getCardById(equip[1]),"@"..choice,1)
                    room:sendLog{
                        type = "#ysch3_shengong-log",
                        from = from.id,
                        arg = self.name,
                        arg2 = Fk:getCardById(equip[1]):toLogString(),
                        arg3 = choice,
                        toast = true,
                    }
                    local mark = {}
                    table.filter(from:getCardIds("e"),function (id)
                        local card = Fk:getCardById(id)
                        local curses = {}
                        for k, v in pairs(card.mark) do
                            if k and k:startsWith("@@ysch3_shengong") and v and v ~= 0 then
                                table.insert(curses,k)
                            end
                        end
                        if #curses > 0 then
                            table.insert(mark,card.name)
                            table.insertTable(mark,curses)
                        end
                    end)
                    if #mark > 0 then
                        room:setPlayerMark(from,"@[curse]ysch3_curse",mark)
                    else
                        room:setPlayerMark(from,"@[curse]ysch3_curse",0)
                    end
                    room:setPlayerMark(from, "ysch3_shengong_cards", equip)
                    local success, dat = room:askForUseActiveSkill(from, "ysch3_shengong_active", "#ysch3_shengong-choose", true)
                    room:setPlayerMark(from, "ysch3_shengong_cards", 0)
                    if dat then
                        from:broadcastSkillInvoke(self.name,table.random({3,6}))
                        local cardId = dat.cards[1]
                        local to = room:getPlayerById(dat.targets[1])
                        room:moveCardIntoEquip(to, cardId, self.name, true, from)
                        from:drawCards(2,self.name)
                    end
                    mark = {}
                    table.filter(from:getCardIds("e"),function (id)
                        local card = Fk:getCardById(id)
                        local curses = {}
                        for k, v in pairs(card.mark) do
                            if k and k:startsWith("@@ysch3_shengong") and v and v ~= 0 then
                                table.insert(curses,k)
                            end
                        end
                        if #curses > 0 then
                            table.insert(mark,card.name)
                            table.insertTable(mark,curses)
                        end
                    end)
                    if #mark > 0 then
                        room:setPlayerMark(from,"@[curse]ysch3_curse",mark)
                    else
                        room:setPlayerMark(from,"@[curse]ysch3_curse",0)
                    end
                end
            else
                room:sendLog({
                    type = "#ysch3_shengong-fail",
                    from = from.id,
                    arg = Fk:getCardById(equip[1]):toLogString(),
                    toast = true,
                })
            end
        end
    end,
}
local shengong_active = fk.CreateActiveSkill{
    name = "ysch3_shengong_active",
    card_num = 1,
    target_num = 1,
    card_filter = function(self, to_select, selected)
        return #selected == 0 and table.contains(Self:getTableMark("ysch3_shengong_cards"), to_select)
    end,
    target_filter = function(self, to_select, selected, selected_cards)
        return #selected == 0 and #selected_cards == 1 and to_select ~= Self.id
        and Fk:currentRoom():getPlayerById(to_select):canMoveCardIntoEquip(selected_cards[1], true)
    end,
}
Fk:addSkill(shengong_active)
puyuan:addSkill(shengong)
---检测有无指定的合法附魔魔咒
---@param card integer | Card @ 卡牌
---@param curse string @ 魔咒
---@param sub_type? integer @ 指定副类别
local function hasCurse(card,curse,sub_type)
    if type(card) == "number" then
        card = Fk:getCardById(card)
    end
    if card.type ~= Card.TypeEquip or (sub_type ~= nil and card.sub_type ~= sub_type) then return false end
    return card:getMark(curse) ~= 0
end
local curse = fk.CreateTriggerSkill{
    name = "#ysch3_curse",
    refresh_events = {fk.AfterCardsMove,fk.TargetSpecified,fk.EventPhaseStart,fk.Damage,fk.CardUsing,fk.DamageInflicted,fk.Damaged,fk.AskForRetrial,fk.BeforeCardsMove,fk.BeforeDrawCard,fk.PreHpRecover,fk.CardEffectCancelledOut},
    can_refresh = function (self, event, target, player, data)
        local equips = player:getCardIds("e")
        local room = player.room
        if event == fk.AfterCardsMove then
            for _, move in ipairs(data) do
                if (move.to == player.id and move.toArea == Card.PlayerEquip) or (move.from == player.id) then
                    for _, info in ipairs(move.moveInfo) do
                        local card = Fk:getCardById(info.cardId)
                        if (move.from == player.id and info.fromArea == Card.PlayerEquip) or move.to == player.id then
                            for k, v in pairs(card.mark) do
                                if k and k:startsWith("@@ysch3_shengong") and v and v ~= 0 then
                                    return true
                                end
                            end
                        end
                    end
                end
            end
        elseif event == fk.TargetSpecified then
            return target == player and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongA1",Card.SubtypeWeapon)
            end) and data.card.is_damage_card
        elseif event == fk.EventPhaseStart then
            if target == player and player.phase == Player.Finish and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongA2",Card.SubtypeWeapon)
            end) then
                local targets = {}
                room.logic:getActualDamageEvents(1, function(e) table.insertIfNeed(targets, e.data[1].to) end)
                targets = table.filter(targets, function(p) return not p.dead end)
                return #targets > 0
            end
        elseif event == fk.Damage then
            if target == player and data.card and data.card.trueName == "slash" and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongA3",Card.SubtypeWeapon)
            end) and not data.to.dead and not data.to:isNude() then
                return true
            end
            if target == player and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongA5",Card.SubtypeWeapon)
            end) and not data.to.dead then
                return true
            end
        elseif event == fk.CardUsing then
            if target == player and data.card.trueName == "slash" and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongA4",Card.SubtypeWeapon)
            end) and data.tos and #data.tos > 0 then
                return true
            end
            if target == player and table.contains({"peach","analeptic"},data.card.trueName) and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongC1")
            end) then
                return true
            end
        elseif event == fk.DamageInflicted then
            if target == player and data.damage > 1 and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongB2",Card.SubtypeArmor)
            end) then
                return true
            end
        elseif event == fk.Damaged then
            if target == player and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongB3",Card.SubtypeArmor)
            end) and data.from and data.from.id ~= player.id and not data.from.dead and not data.from:isNude() then
                return true
            end
        elseif event == fk.AskForRetrial then
            return target == player and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongC2")
            end)
        elseif event == fk.BeforeCardsMove then
            if table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongD1",Card.SubtypeWeapon)
            end) then
                for _, move in ipairs(data) do
                    if move.from == player.id and move.moveReason == fk.ReasonUse then
                        for _, info in ipairs(move.moveInfo) do
                            local card = Fk:getCardById(info.cardId)
                            if card.trueName == "slash" then
                                return true
                            end
                        end
                    end
                end
            end
        elseif event == fk.BeforeDrawCard then
            local events = player.room.logic:getEventsOfScope(GameEvent.MoveCards, 2, function(e)
                local data = e.data
                for _, move in ipairs(data) do
                    if move.to == player.id and move.moveReason == fk.ReasonDraw then
                        return true
                    end
                end
                return false
            end, Player.HistoryTurn)
            return table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongC5")
            end) and target == player and #events == 0
        elseif event == fk.PreHpRecover then
            if target == player then
                for _, id in ipairs(equips) do
                    local curse = {}
                    local card = Fk:getCardById(id)
                    for k, v in pairs(card.mark) do
                        if k and k:startsWith("@@ysch3_shengong") and v and v ~= 0 then
                            table.insert(curse,k)
                        end
                    end
                    if #curse < 5 and hasCurse(id,"@@ysch3_shengongC6") then
                        return true
                    end
                end
            end
        elseif event == fk.CardEffectCancelledOut then
            if target == player and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongD2",Card.SubtypeOffensiveRide) or hasCurse(id,"@@ysch3_shengongD2",Card.SubtypeDefensiveRide)
            end) and room:getPlayerById(data.to) and room:getPlayerById(data.to):isAlive() then
                return true
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local equips = player:getCardIds("e")
        if event == fk.AfterCardsMove then
            for _, move in ipairs(data) do
                if (move.to == player.id and move.toArea == Card.PlayerEquip) then
                    local mark = {}
                    table.filter(equips,function (id)
                        local card = Fk:getCardById(id)
                        local curse = {}
                        for k, v in pairs(card.mark) do
                            if k and k:startsWith("@@ysch3_shengong") and v and v ~= 0 then
                                table.insert(curse,k)
                            end
                        end
                        if #curse > 0 then
                            table.insert(mark,card.name)
                            table.insertTable(mark,curse)
                        end
                    end)
                    if #mark > 0 then
                        room:setPlayerMark(player,"@[curse]ysch3_curse",mark)
                    else
                        room:setPlayerMark(player,"@[curse]ysch3_curse",0)
                    end
                    for _, info in ipairs(move.moveInfo) do
                        local card = Fk:getCardById(info.cardId)
                        if hasCurse(card,"@@ysch3_shengongB1",Card.SubtypeArmor) then
                            if not player.dead then
                                room:changeShield(player, 1)
                            end
                        end
                    end
                elseif move.from == player.id then
                    local mark = {}
                    table.filter(player:getCardIds("e"),function (id)
                        local card = Fk:getCardById(id)
                        local curse = {}
                        for k, v in pairs(card.mark) do
                            if k and k:startsWith("@@ysch3_shengong") and v and v ~= 0 then
                                table.insert(curse,k)
                            end
                        end
                        if #curse > 0 then
                            table.insert(mark,card.name)
                            table.insertTable(mark,curse)
                        end
                    end)
                    if #mark > 0 then
                        room:setPlayerMark(player,"@[curse]ysch3_curse",mark)
                    else
                        room:setPlayerMark(player,"@[curse]ysch3_curse",0)
                    end
                    local gain = {}
                    for _, info in ipairs(move.moveInfo) do
                        if hasCurse(info.cardId,"@@ysch3_shengongC3") and (move.to ~= player.id or move.toArea ~= Card.PlayerHand) and Fk:getCardById(info.cardId):getMark("ysch3_shengongC3-turn") == 0 then
                            room:setCardMark(Fk:getCardById(info.cardId),"ysch3_shengongC3-turn",1)
                            table.insertIfNeed(gain,info.cardId)
                        end
                    end
                    if #gain > 0 then
                        room:moveCardTo(gain,Card.PlayerHand,player,fk.ReasonJustMove, "@@ysch3_shengongC3", nil, true, player.id)
                    end
                end
            end
        elseif event == fk.TargetSpecified then
            room:addPlayerMark(room:getPlayerById(data.to), fk.MarkArmorNullified)
            data.extra_data = data.extra_data or {}
            data.extra_data.qinggangNullified = data.extra_data.qinggangNullified or {}
            data.extra_data.qinggangNullified[tostring(data.to)] = (data.extra_data.qinggangNullified[tostring(data.to)] or 0) + 1
        elseif event == fk.EventPhaseStart then
            local targets = {}
            room.logic:getActualDamageEvents(1, function(e) table.insertIfNeed(targets, e.data[1].to) end)
            targets = table.filter(targets, function(tp) return not tp.dead end)
            for _, tp in ipairs(targets) do
                room:damage({
                    from = player,
                    to = tp,
                    damage = 1,
                    damageType = fk.FireDamage,
                    skillName = nil,
                })
            end
        elseif event == fk.Damage then
            if target == player and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongA5",Card.SubtypeWeapon)
            end) and not data.to.dead then
                room:addPlayerMark(data.to, "@[desc]ysch3_dun-round")
            end
            if target == player and data.card and data.card.trueName == "slash" and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongA3",Card.SubtypeWeapon)
            end) and not data.to.dead and not data.to:isNude() then
                local id = room:askForCardChosen(player, data.to, "he", "@@ysch3_shengongA3","@@ysch3_shengongA3-prompt")
                if id ~= -1 then
                    room:obtainCard(player,id,false)
                end
            end
        elseif event == fk.CardUsing then
            if target == player and data.card.type == Card.TypeBasic and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongC1")
            end) then
                if data.card.name == "peach" then
                    data.additionalRecover = (data.additionalRecover or 0) + 1
                elseif data.card.name == "analeptic" then
                    if data.extra_data and data.extra_data.analepticRecover then
                        data.additionalRecover = (data.additionalRecover or 0) + 1
                    else
                        data.extra_data = data.extra_data or {}
                        data.extra_data.additionalDrank = (data.extra_data.additionalDrank or 0) + 1
                    end
                end
            end
            if target == player and data.card.trueName == "slash" and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongA4",Card.SubtypeWeapon)
            end) and data.tos and #data.tos > 0 then
                room.tag["@@ysch3_shengongA4"] = room.tag["@@ysch3_shengongA4"] or {}
                room.tag["@@ysch3_shengongA4"][player.id] = room.tag["@@ysch3_shengongA4"][player.id] or 0
                if not player.dead then
                    local judge = {
                        who = player,
                        reason = "floating_thunder",
                        pattern = ".|.|spade",
                    }
                    room:judge(judge)
                    if judge.card.suit == Card.Spade then
                        room.tag["@@ysch3_shengongA4"][player.id] = room.tag["@@ysch3_shengongA4"][player.id] + 1
                        room:damage{
                            to = player,
                            damage = room.tag["@@ysch3_shengongA4"][player.id],
                            damageType = fk.ThunderDamage,
                            skillName = "@@ysch3_shengongA4",
                        }
                    end
                end
                for _, id in ipairs(TargetGroup:getRealTargets(data.tos)) do
                    local tp = room:getPlayerById(id)
                    room.tag["@@ysch3_shengongA4"][id] = room.tag["@@ysch3_shengongA4"][id] or 0
                    if not tp.dead then
                        local judge = {
                            who = tp,
                            reason = "floating_thunder",
                            pattern = ".|.|spade",
                        }
                        room:judge(judge)
                        if judge.card.suit == Card.Spade then
                            room.tag["@@ysch3_shengongA4"][id] = room.tag["@@ysch3_shengongA4"][id] + 1
                            room:damage{
                                to = tp,
                                damage = room.tag["@@ysch3_shengongA4"][id],
                                damageType = fk.ThunderDamage,
                                skillName = "@@ysch3_shengongA4",
                            }
                        end
                    end
                end
            end
        elseif event == fk.DamageInflicted then
            room:sendLog{
                type = "#BreastplateSkill",
                from = player.id,
                arg = "@@ysch3_shengongB2",
                arg2 = data.damage,
                arg3 = Fk:getDamageNatureName(data.damageType),
            }
            room:moveCardTo(table.filter(equips, function(id) return hasCurse(id,"@@ysch3_shengongB2",Card.SubtypeArmor) end),
            Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
            local mark = {}
            table.filter(equips,function (id)
                local card = Fk:getCardById(id)
                local curse = {}
                for k, v in pairs(card.mark) do
                    if k and k:startsWith("@@ysch3_shengong") and v and v ~= 0 then
                        table.insert(curse,k)
                    end
                end
                if #curse > 0 then
                    table.insert(mark,card.name)
                    table.insertTable(mark,curse)
                end
            end)
            if #mark > 0 then
                room:setPlayerMark(player,"@[curse]ysch3_curse",mark)
            else
                room:setPlayerMark(player,"@[curse]ysch3_curse",0)
            end
            data.damage = -999
            return true
        elseif event == fk.Damaged then
            local cid = room:askForCardChosen(player, data.from, "he", "@@ysch3_shengongB3", "@@ysch3_shengongB3-prompt")
            room:throwCard({cid}, self.name, data.from, player)
        elseif event == fk.AskForRetrial then
            for _, id in ipairs(equips) do
                if hasCurse(id,"@@ysch3_shengongC2") then
                    if room:askForSkillInvoke(player,"@@ysch3_shengongC2",nil,"@@ysch3_shengongC2-prompt") then
                        local move1 = {
                            ids = room:getNCards(1),
                            toArea = Card.Processing,
                            moveReason = fk.ReasonJustMove,
                            skillName = "@@ysch3_shengongC2",
                            proposer = player.id,
                        }
                        local move2 = {
                            ids = {data.card:getEffectiveId()},
                            toArea = Card.DiscardPile,
                            moveReason = fk.ReasonJustMove,
                            skillName = "@@ysch3_shengongC2",
                        }
                        room:moveCards(move1, move2)
                        data.card = Fk:getCardById(move1.ids[1])
                        room:sendLog{
                            type = "#ChangedJudge",
                            from = player.id,
                            to = {player.id},
                            card = {move1.ids[1]},
                            arg = "@@ysch3_shengongC2",
                        }
                    else
                        break
                    end
                end
            end
        elseif event == fk.BeforeCardsMove then
            for _, move in ipairs(data) do
                if move.from == player.id and move.moveReason == fk.ReasonUse then
                    local move_info = {}
                    for _, info in ipairs(move.moveInfo) do
                        if Fk:getCardById(info.cardId).name ~= "slash" then
                            table.insert(move_info, info)
                        end
                    end
                    move.moveInfo = move_info
                end
            end
        elseif event == fk.BeforeDrawCard then
            data.num = 4
            local drawEvent = room.logic:getCurrentEvent().parent
            if data.skillName == "recast" then
                drawEvent = room.logic:getCurrentEvent()
            end
            drawEvent:addCleaner(function ()
                room:askForDiscard(player, 2, 2, true, self.name, false, ".")
            end)
        elseif event == fk.PreHpRecover then
            if target == player then
                for _, id in ipairs(equips) do
                    local curses = {}
                    local card = Fk:getCardById(id)
                    for k, v in pairs(card.mark) do
                        if k and k:startsWith("@@ysch3_shengong") and v and v ~= 0 then
                            table.insert(curses,k)
                        end
                    end
                    if #curses < 5 and hasCurse(id,"@@ysch3_shengongC6") then
                        local sub_type = card.sub_type
                        local curse = {}
                        if sub_type == Card.SubtypeWeapon then
                            curse = {"@ysch3_shengongA1","@ysch3_shengongA2","@ysch3_shengongA3","@ysch3_shengongA4","@ysch3_shengongA5",
                            "@ysch3_shengongC1","@ysch3_shengongC2","@ysch3_shengongC3","@ysch3_shengongC4","@ysch3_shengongC5","@ysch3_shengongC6"}
                            --[[if string.find(Fk:translate(card.name, "zh_CN"), "弓") ~= nil then
                                table.insert(curse,"@ysch3_shengongD1")
                            end]]--
                        elseif sub_type == Card.SubtypeArmor then
                            curse = {"@ysch3_shengongB1","@ysch3_shengongB2","@ysch3_shengongB3","@ysch3_shengongB4",
                            "@ysch3_shengongC2","@ysch3_shengongC3","@ysch3_shengongC4","@ysch3_shengongC6"}
                        elseif table.contains({Card.SubtypeOffensiveRide,Card.SubtypeDefensiveRide},sub_type) then
                            curse = {"@ysch3_shengongB2","@ysch3_shengongD2",
                            "@ysch3_shengongC2","@ysch3_shengongC3","@ysch3_shengongC4","@ysch3_shengongC6"}
                        else
                            curse = {"@ysch3_shengongC1","@ysch3_shengongC2","@ysch3_shengongC3","@ysch3_shengongC4","@ysch3_shengongC6"}
                        end
                        for _, str in ipairs(curse) do
                            if card:getMark("@"..str) == 1 then
                                table.removeOne(curse,str)
                            end
                        end
                        if #curse > 0 then
                            local choice = table.random(curse)
                            room:setCardMark(card,"@"..choice,1)
                            room:sendLog{
                                type = "#ysch3_shengong-log",
                                from = player.id,
                                arg = "@@ysch3_shengongC6",
                                arg2 = card:toLogString(),
                                arg3 = choice,
                                toast = true,
                            }
                        end
                    end
                end
                local mark = {}
                table.filter(equips,function (id)
                    local card = Fk:getCardById(id)
                    local curse = {}
                    for k, v in pairs(card.mark) do
                        if k and k:startsWith("@@ysch3_shengong") and v and v ~= 0 then
                            table.insert(curse,k)
                        end
                    end
                    if #curse > 0 then
                        table.insert(mark,card.name)
                        table.insertTable(mark,curse)
                    end
                end)
                if #mark > 0 then
                    room:setPlayerMark(player,"@[curse]ysch3_curse",mark)
                else
                    room:setPlayerMark(player,"@[curse]ysch3_curse",0)
                end
            end
        elseif event == fk.CardEffectCancelledOut then
            if target == player and table.find(equips,function (id)
                return hasCurse(id,"@@ysch3_shengongD2",Card.SubtypeOffensiveRide) or hasCurse(id,"@@ysch3_shengongD2",Card.SubtypeDefensiveRide)
            end) and room:getPlayerById(data.to) and room:getPlayerById(data.to):isAlive() then
                local target = room:getPlayerById(data.to)
                room:damage {
                    from = target,
                    to = target,
                    damage = 1,
                    damageType = fk.IceDamage,
                }
            end
        end
    end,
    global = true,
}
local curse_prohibit = fk.CreateProhibitSkill{
    name = "#ysch3_curse_prohibit",
    prohibit_use = function(self, player, card)
        if card.type == Card.TypeEquip then
            local equips = player:getCardIds("e")
            for _, id in ipairs(equips) do
                local equip = Fk:getCardById(id)
                if equip:getMark("@@ysch3_shengongC4") == 1 and equip.sub_type == card.sub_type then
                    return true
                end
            end
        end
    end,
    global = true,
}
local curse_maxcards = fk.CreateMaxCardsSkill{
    name = "#ysch3_curse_maxcards",
    global = true,
    correct_func = function(self, player)
        local equips = player:getCardIds("e")
        local add = 0
        for _, id in ipairs(equips) do
            local equip = Fk:getCardById(id)
            if equip:getMark("@@ysch3_shengongB4") == 1 then
                add = add + 2
            end
        end
        return add
    end,
}
local dunxi = fk.CreateTriggerSkill{
    name = "#ysch3_dunxi",
    mute = true,
    global = true,
    anim_type = "negative",
    events = {fk.CardUsing, fk.CardUseFinished},
    can_trigger = function(self, event, target, player, data)
        if event == fk.CardUsing then
            if player == target and player:getMark("@[desc]ysch3_dun-round") > 0 and
            (data.card.type == Card.TypeBasic or data.card.type == Card.TypeTrick) and #TargetGroup:getRealTargets(data.tos) == 1 then
                for _, p in ipairs(player.room.alive_players) do
                if p.dying then
                    return false
                end
                end
                return true
            end
        elseif event == fk.CardUseFinished then
            return not player.dead and data.extra_data and data.extra_data.dunxi_record and
                table.contains(data.extra_data.dunxi_record, player.id)
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if event == fk.CardUsing then
            room:removePlayerMark(player, "@[desc]ysch3_dun-round")
            local orig_to = data.tos[1]
            local targets = {}
            local c_pid
            for _, p in ipairs(room.alive_players) do
                if not player:isProhibited(p, data.card) and
                (data.card.sub_type == Card.SubtypeDelayedTrick or data.card.skill:modTargetFilter(p.id, {}, player, data.card, true)) then
                local ho_spair_check = true
                if #orig_to > 1 then
                    --target_filter check, for collateral, diversion...
                    local ho_spair_target = {p.id}
                    for i = 2, #orig_to, 1 do
                    c_pid = orig_to[i]
                    if not data.card.skill:modTargetFilter(c_pid, ho_spair_target, player, data.card, true) then
                        ho_spair_check = false
                        break
                    end
                    table.insert(ho_spair_target, c_pid)
                    end
                end
                if ho_spair_check then
                    table.insert(targets, p.id)
                end
                end
            end
            if #targets > 0 then
                local random_target = table.random(targets)
                for i = 1, 2, 1 do
                for _, p in ipairs(room:getAllPlayers()) do
                    if table.contains(targets, p.id) then
                    room:setEmotion(p, "./image/anim/selectable")
                    room:notifyMoveFocus(p, self.name)
                    room:delay(300)
                    end
                end
                end
                for _, p in ipairs(room:getAllPlayers()) do
                if table.contains(targets, p.id) then
                    room:setEmotion(p, "./image/anim/selectable")
                    room:delay(600)
                    if p.id == random_target then
                    room:doIndicate(data.from, {random_target})
                    break
                    end
                end
                end
        
                if random_target == orig_to[1] then
                data.extra_data = data.extra_data or {}
                local dunxi_record = data.extra_data.dunxi_record or {}
                table.insert(dunxi_record, player.id)
                data.extra_data.dunxi_record = dunxi_record
                else
                orig_to[1] = random_target
                data.tos = { orig_to }
                end
            else
                data.tos = {}
            end
        elseif event == fk.CardUseFinished then
            room:loseHp(player, 1, self.name)
            if player.phase == Player.Play then
                player:endPlayPhase()
            end
        end
    end,
}
Fk:addSkill(curse)
Fk:addSkill(curse_prohibit)
Fk:addSkill(curse_maxcards)
Fk:addSkill(dunxi)
local tianjiang = fk.CreateTriggerSkill{
    name = "ysch3_tianjiang",
    anim_type = "drawcard",
    mute = true,
    events = {fk.GameStart, fk.DrawNCards},
    can_trigger = function(self, event, target, player, data)
        if event == fk.GameStart then
            return player:hasSkill(self)
        else
            return player:hasSkill(self) and target == player and data.n > 0
        end
    end,
    on_cost = function (self, event, target, player, data)
        if event == fk.GameStart then
            return true
        else
            local room = player.room
            local choices = {"treasure", "weapon", "armor", "defensive_horse", "offensive_horse", "Cancel"}
            local choice = room:askForChoice(player, choices, self.name, "#ysch3_tianjiang-invoke")
            if choice ~= "Cancel" then
                self.cost_data = choice
                return true
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if event == fk.GameStart then
            local equipMap = {}
            for _, id in ipairs(room.draw_pile) do
                local sub_type = Fk:getCardById(id).sub_type
                if Fk:getCardById(id).type == Card.TypeEquip and player:hasEmptyEquipSlot(sub_type) then
                    local list = equipMap[tostring(sub_type)] or {}
                    table.insert(list, id)
                    equipMap[tostring(sub_type)] = list
                end
            end
            local types = {}
            for k, _ in pairs(equipMap) do
                table.insert(types, k)
            end
            if #types == 0 then return end
            types = table.random(types, 2)
            local put = {}
            for _, t in ipairs(types) do
                table.insert(put, table.random(equipMap[t]))
            end
            room:notifySkillInvoked(player,self.name,"drawcard")
            player:broadcastSkillInvoke(self.name,1)
            room:moveCardIntoEquip(player, put, self.name, false, player)
        else
            room:notifySkillInvoked(player,self.name,"drawcard")
            player:broadcastSkillInvoke(self.name,table.random({2,3}))
            local StrToSubtypeList = {["weapon"]={Card.SubtypeWeapon},["armor"]={Card.SubtypeArmor},["treasure"]={Card.SubtypeTreasure},["offensive_horse"]={Card.SubtypeOffensiveRide},["defensive_horse"]={Card.SubtypeDefensiveRide}}
            local choice = self.cost_data
            local list = StrToSubtypeList[choice]
            local cards = {}
            if math.random() > 0.3 then
                local piles = table.simpleClone(room.draw_pile)
                table.insertTable(piles, room.discard_pile)
                for _, id in ipairs(piles) do
                    if table.contains(list, Fk:getCardById(id).sub_type) then
                        table.insert(cards, id)
                    end
                end
            else
                local ingame = getAllCardNames("e")
                local banned = {"kingsbane","poisonous_dagger","crossbow"}
                for _, card in ipairs(Fk.cards) do
                    local name = card.name
                    if card and card.type == Card.TypeEquip and table.contains(list, card.sub_type) and not table.contains(banned,name) then
                        --print(Util.TranslateMapper(name))
                        if not table.find(ingame, function (ingamename)
                        return ingamename == name
                        end) then
                            if #table.filter(cards,function(cid)
                                local card1=Fk:getCardById(cid)
                                return card1.name == card.name
                            end) == 0 then
                                local c = room:printCard(name, card.suit, card.number)
                                room:setCardMark(c, MarkEnum.DestructIntoDiscard, 1)
                                table.insertIfNeed(cards, c.id)
                            end
                        end
                    end
                end
            end
            if #cards == 0 then return end
            room:moveCardTo(table.random(cards), Card.PlayerHand, player, fk.ReasonPrey, self.name)
            data.n = data.n - 1
        end
    end,
}
puyuan:addSkill(tianjiang)
local puyuan_win = fk.CreateActiveSkill{ name = "ysch3__puyuan_win_audio" }
puyuan_win.package = extension
Fk:addSkill(puyuan_win)
Fk:loadTranslationTable{
    ["ysch3_shengong"] = "神工",
    [":ysch3_shengong"] = "出牌阶段限三次，你可以弃置一张牌并展示一张少于三条<a href=':ysch3_shengong_curse'>魔咒</a>的装备牌，从三条随机魔咒中选择一条<a href=':ysch3_tianjiang_curse'>附魔</a>之，然后你可将此牌置入其他角色装备区并摸两张牌。",
    ["@[curse]ysch3_curse"] = "附魔",
    ["#ysch3_shengong-prompt"] = "是否发动 神工，弃置一张牌并为一张装备牌附魔",
    ["#ysch3_shengong-curse"] = "神工：请选择一条魔咒",
    ["#ysch3_shengong-choose"] = "神工：你可以令一名其他角色装备此牌，然后你摸两张牌",
    ["ysch3_shengong_active"] = "神工",
    ["#ysch3_shengong-log"] = "%from 发动了〖%arg〗，为 %arg2 附魔了 %arg3",
    ["#ysch3_shengong-fail"] = "%arg 已经没有可附魔的魔咒了",
    ["ysch3_tianjiang"] = "天匠",
    [":ysch3_tianjiang"] = "游戏开始时，将两张不同副类别的装备牌置入你的装备区。摸牌阶段，你可以检索一张指定副类别的装备，若成功，你获得并少摸一张牌。",
    ["#ysch3_tianjiang-invoke"] = "天匠：你可以声明并获得一种副类别的装备",
    [":ysch3_shengong_curse"] = "魔咒——"..
    "<br><b>锋利</b>：你使用伤害牌无视目标防具。"..
    "<br><b>火焰附加</b>：结束阶段，本回合受到过伤害的角色受到1点火焰伤害。"..
    "<br><b>掠夺</b>：你使用【杀】造成伤害后，获得目标一张牌。"..
    "<br><b>引雷</b>：你使用【杀】时，与目标进行“浮雷”判定。"..
    "<br><b>击退</b>：你造成伤害后，目标获得一个“<a href=':ysch3_dun-round'>钝</a>”标记至本轮结束。"..
    "<br><b>保护</b>：此装备进入你的装备区时，你获得1点护甲。"..
    "<br><b>缓冲</b>：你受到大于1点的伤害时，弃置此牌防止之。"..
    "<br><b>荆棘</b>：你受到其他角色的伤害后，弃置伤害来源一张牌。"..
    "<br><b>水下呼吸</b>：你的手牌上限+2。"..
    "<br><b>效率</b>：你使用【桃】或【酒】时，牌面数值+1。"..
    "<br><b>时运</b>：你的判定牌生效前，可以亮出牌堆顶的一张牌代替之。"..
    "<br><b>忠诚</b>：此牌本回合首次离开装备区后，置入你的手牌区。"..
    "<br><b>绑定诅咒</b>：你不能再使用相同副类别的装备牌。"..
    "<br><b>精准采集</b>：每回合首次摸牌时，改为摸四张牌再弃置两张牌。"..
    "<br><b>经验修补</b>：此装备魔咒上限为5，你回复体力时，为此装备再添加1条魔咒。"..
    "<br><b>无限</b>：你因使用失去【杀】时，防止之。"..
    "<br><b>冰霜行者</b>：你抵消牌后，使用者对其自己造成1点冰冻伤害。",
    [":ysch3_tianjiang_curse"] = "魔咒适用性——"..
    "<br><b>武器</b>：锋利、火焰附加、掠夺、引雷、击退、效率、精准采集"..
    "<br>※牌名含“弓”的武器：无限（不与经验修补兼容）"..
    "<br><b>防具</b>：保护、缓冲、荆棘、水下呼吸"..
    "<br><b>坐骑</b>：缓冲、冰霜行者"..
    "<br><b>宝物</b>：效率"..
    "<br><b>通用</b>：时运、忠诚、绑定诅咒、经验修补",

    ["@ysch3_shengongA1"] = "锋利",
    [":@ysch3_shengongA1"] = "你使用伤害牌无视目标防具。",
    ["@ysch3_shengongA2"] = "火焰附加",
    [":@ysch3_shengongA2"] = "结束阶段，本回合受到过伤害的角色受到1点火焰伤害。",
    ["@ysch3_shengongA3"] = "掠夺",
    [":@ysch3_shengongA3"] = "你使用【杀】造成伤害后，获得目标一张牌。",
    ["@ysch3_shengongA3-prompt"] = "掠夺：获得目标一张牌",
    ["@ysch3_shengongA4"] = "引雷",
    [":@ysch3_shengongA4"] = "你使用【杀】时，与目标进行“浮雷”判定。",
    ["@ysch3_shengongA5"] = "击退",
    [":@ysch3_shengongA5"] = "你造成伤害后，目标获得一个“钝”标记至本轮结束。",

    ["@ysch3_shengongB1"] = "保护",
    [":@ysch3_shengongB1"] = "此装备进入你的装备区时，你获得1点护甲。",
    ["@ysch3_shengongB2"] = "缓冲",
    [":@ysch3_shengongB2"] = "你受到大于1点的伤害时，弃置此牌防止之。",
    ["@ysch3_shengongB3"] = "荆棘",
    [":@ysch3_shengongB3"] = "你受到其他角色的伤害后，弃置伤害来源一张牌。",
    ["@ysch3_shengongB4"] = "水下呼吸",
    [":@ysch3_shengongB4"] = "你的手牌上限+2。",

    ["@ysch3_shengongC1"] = "效率",
    [":@ysch3_shengongC1"] = "你使用【桃】或【酒】时，牌面数值+1。",
    ["@ysch3_shengongC2"] = "时运",
    [":@ysch3_shengongC2"] = "你的判定牌生效前，可以亮出牌堆顶的一张牌代替之。",
    ["@ysch3_shengongC3"] = "忠诚",
    [":@ysch3_shengongC3"] = "此牌本回合首次离开装备区后，置入你的手牌区。",
    ["@ysch3_shengongC4"] = "绑定诅咒",
    [":@ysch3_shengongC4"] = "你不能再使用相同副类别的装备牌。",
    ["@ysch3_shengongC5"] = "精准采集",
    [":@ysch3_shengongC5"] = "每回合首次摸牌时，改为摸四张牌再弃置两张牌。",
    ["@ysch3_shengongC6"] = "经验修补",
    [":@ysch3_shengongC6"] = "此装备魔咒上限为5，你回复体力时，为此装备再添加1条魔咒。",

    ["@ysch3_shengongD1"] = "无限",
    [":@ysch3_shengongD1"] = "你因使用失去【杀】时，防止之。",
    ["@ysch3_shengongD2"] = "冰霜行者",
    [":@ysch3_shengongD2"] = "你抵消牌后，使用者对其自己造成1点冰冻伤害。",

    ["@@ysch3_shengongA1"] = "锋利",
    [":@@ysch3_shengongA1"] = "<font color='#cd9bff'>你使用伤害牌无视目标防具。",
    ["@@ysch3_shengongA2"] = "火焰附加",
    [":@@ysch3_shengongA2"] = "<font color='#cd9bff'>结束阶段，本回合受到过伤害的角色受到1点火焰伤害。",
    ["@@ysch3_shengongA3"] = "掠夺",
    [":@@ysch3_shengongA3"] = "<font color='#cd9bff'>你使用【杀】造成伤害后，获得目标一张牌。",
    ["@@ysch3_shengongA3-prompt"] = "掠夺：获得目标一张牌",
    ["@@ysch3_shengongA4"] = "引雷",
    [":@@ysch3_shengongA4"] = "<font color='#cd9bff'>你使用【杀】时，与目标进行“浮雷”判定。",
    ["floating_thunder"] = "浮雷",
    ["@@ysch3_shengongA5"] = "击退",
    [":@@ysch3_shengongA5"] = "<font color='#cd9bff'>你造成伤害后，目标获得一个“钝”标记至本轮结束。",
    ["@[desc]ysch3_dun-round"] = "钝",
    ["#ysch3_dunxi"] = "钝袭",
    [":ysch3_dun-round"] = "有“钝”标记的角色使用基本牌或锦囊牌时，"..
    "若目标数为1且没有处于濒死状态的角色，其移去一个“钝”，然后目标改为随机一名角色。"..
    "若随机的目标与原本目标相同，则其于此牌结算结束后失去1点体力并结束出牌阶段。",

    ["@@ysch3_shengongB1"] = "保护",
    [":@@ysch3_shengongB1"] = "<font color='#cd9bff'>此装备进入你的装备区时，你获得1点护甲。",
    ["@@ysch3_shengongB2"] = "缓冲",
    [":@@ysch3_shengongB2"] = "<font color='#cd9bff'>你受到大于1点的伤害时，弃置此牌防止之。",
    ["@@ysch3_shengongB3"] = "荆棘",
    [":@@ysch3_shengongB3"] = "<font color='#cd9bff'>你受到其他角色的伤害后，弃置伤害来源一张牌。",
    ["@@ysch3_shengongB3-prompt"] = "荆棘：弃置伤害来源一张牌",
    ["@@ysch3_shengongB4"] = "水下呼吸",
    [":@@ysch3_shengongB4"] = "<font color='#cd9bff'>你的手牌上限+2。",

    ["@@ysch3_shengongC1"] = "效率",
    [":@@ysch3_shengongC1"] = "<font color='#cd9bff'>你使用【桃】或【酒】时，牌面数值+1。",
    ["@@ysch3_shengongC2"] = "时运",
    [":@@ysch3_shengongC2"] = "<font color='#cd9bff'>你的判定牌生效前，可以亮出牌堆顶的一张牌代替之。",
    ["@@ysch3_shengongC2-prompt"] = "是否发动 时运，亮出牌堆顶的一张牌代替判定牌",
    ["@@ysch3_shengongC3"] = "忠诚",
    [":@@ysch3_shengongC3"] = "<font color='#cd9bff'>此牌本回合首次离开装备区后，置入你的手牌区。",
    ["@@ysch3_shengongC4"] = "绑定诅咒",
    [":@@ysch3_shengongC4"] = "<font color='#800000'>你不能再使用相同副类别的装备牌。",
    ["@@ysch3_shengongC5"] = "精准采集",
    [":@@ysch3_shengongC5"] = "<font color='#cd9bff'>每回合首次摸牌时，改为摸四张牌再弃置两张牌。",
    ["@@ysch3_shengongC6"] = "经验修补",
    [":@@ysch3_shengongC6"] = "<font color='#cd9bff'>此装备魔咒上限为5，你回复体力时，为此装备再添加1条魔咒。",

    ["@@ysch3_shengongD1"] = "无限",
    [":@@ysch3_shengongD1"] = "<font color='#cd9bff'>你因使用失去【杀】时，防止之。",
    ["@@ysch3_shengongD2"] = "冰霜行者",
    [":@@ysch3_shengongD2"] = "<font color='#cd9bff'>你抵消牌后，使用者对其自己造成1点冰冻伤害。",

    ["$ysch3_shengong1"] = "这场表演你们喜欢吗？呵呵呵呵……你们当然喜欢。",
    ["$ysch3_shengong2"] = "你的设计工艺感很强，外观是不错的。但如果你想再提升一下格调……我有不少主意。",
    ["$ysch3_shengong3"] = "等会玩得开心……",
    ["$ysch3_shengong4"] = "善后工作我是不负责的……",
    ["$ysch3_shengong5"] = "这下他们该紧张了……",
    ["$ysch3_shengong6"] = "一点薄礼……",
    ["$ysch3_tianjiang1"] = "我知道怎样才是华丽的登场。",
    ["$ysch3_tianjiang2"] = "这些枪都还可以，不过……无意冒犯，我还是自备了一些。",
    ["$ysch3_tianjiang3"] = "好吧，这次选哪吧枪呢？",
    ["ysch3__puyuan_win_audio"] = "胜利语音",
    ["$ysch3__puyuan_win_audio"] = "他们走不了了！",
}

local lingcao = General:new(extension, "ysch3__lingcao", "wu", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__lingcao"] = "凌操",
    ["#ysch3__lingcao"] = "激流奋孤胆",
    ["designer:ysch3__lingcao"] = "铝",
    ["cv:ysch3__lingcao"] = "官方",
    ["illustrator:ysch3__lingcao"] = "樱花闪乱",
}
local dujin = fk.CreateTriggerSkill{
    name = "ysch3_dujin",
    anim_type = "drawcard",
    events = {fk.CardUseFinished},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and target == player and data.extra_data and (data.extra_data.ysch3_dujin3 or data.extra_data.ysch3_dujin1)
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if data.extra_data.ysch3_dujin3 then room:setPlayerMark(player,"@ysch3_dujin-turn",0) end
        if data.extra_data.ysch3_dujin3 and data.extra_data.ysch3_dujin1 then
            for i = 1, 3, 1 do
                local cards = room:getCardsFromPileByRule(".", 3, "allPiles")
                local result = room:askForCardChosen(player, player, { card_data = { { self.name, table.random(cards, 3) } } }, self.name, "#ysch3_dujin-card")
                room:obtainCard(player,result,false)
            end
        else
            player:drawCards(3,self.name)
        end
    end,

    refresh_events = {fk.PreCardUse,fk.CardUsing},
    can_refresh = function (self, event, target, player, data)
        if event == fk.CardUsing then return player:hasSkill(self.name) end
        if player == target and player:hasSkill(self.name) then
            local room = player.room
            local num = 0
            room.logic:getEventsOfScope(GameEvent.UseCard, 4, function(e)
                num = num + 1
                return true
            end, Player.HistoryTurn)
            local draw = true
            for _, id in ipairs(player:getCardIds("h")) do
                if data.card.id ~= id or (type(data.card.subcards) == "table" and #data.card.subcards > 0 and not table.contains(data.card.subcards,id)) then
                    draw = false
                end
            end
            return num == 3 or draw == true
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local num = 0
        room.logic:getEventsOfScope(GameEvent.UseCard, 4, function(e)
            num = num + 1
            return true
        end, Player.HistoryTurn)
        if event == fk.CardUsing then
            if num > 3 then
                room:setPlayerMark(player,"@ysch3_dujin-turn",0)
            else
                room:setPlayerMark(player,"@ysch3_dujin-turn",num)
            end
        else
            if player == target then
                data.extra_data = data.extra_data or {}
                local draw = true
                for _, id in ipairs(player:getCardIds("h")) do
                    if data.card.id ~= id or (type(data.card.subcards) == "table" and #data.card.subcards > 0 and not table.contains(data.card.subcards,id)) then
                        p(id)
                        draw = false
                        break
                    end
                end
                p(draw)
                data.extra_data.ysch3_dujin1 = draw
                if num == 3 then data.extra_data.ysch3_dujin3 = true end
            end
        end
    end,
}
lingcao:addSkill(dujin)
Fk:loadTranslationTable{
    ["ysch3_dujin"] = "独进",
    [":ysch3_dujin"] = "你使用本回合第三或唯一一张手牌后摸三张牌，若均满足，改为发现三张。",
    ["#ysch3_dujin-card"] = "独进：选择一张牌获得",
    ["@ysch3_dujin-turn"] = "独进",

    ["$ysch3_dujin1"] = "带兵十万，不如老夫多甲一件！",
    ["$ysch3_dujin2"] = "轻舟独进，破敌先锋！",
    ["~ysch3__lingcao"] = "呃啊！（扑通）此箭……何来……",
}
local wangbi = General:new(extension, "ysch3__wangbi", "wei", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__wangbi"] = "王必",
    ["#ysch3__wangbi"] = "忠血辟荆",
    ["designer:ysch3__wangbi"] = "铝",
    ["cv:ysch3__wangbi"] = "无",
    ["illustrator:ysch3__wangbi"] = "未知",
}
--- 移动某角色区域内一张牌
---@param from ServerPlayer @ 被移动牌的角色
---@param proposer ServerPlayer @ 操控者
---@param skillName string @ 技能名
---@param cancelable boolean @ 是否可取消，默认可取消
---@return table<"cardID"|"to">? @ 被移动的牌id，可能为空
local askForMoveCardFromPlayerArea = function (from, proposer, skillName, cancelable)
    local room = from.room
    if from:isAllNude() or table.every(room.alive_players, function(p) return p == from end) then return end
    cancelable = cancelable == nil or cancelable
    local targets = table.filter(room.alive_players, function(p) return from:canMoveCardsInBoardTo(p, nil) end)
    local choices = {}
    if not from:isKongcheng() then table.insert(choices, "#ysch3_moveHand:"..from.id) end
    if #targets > 0 then table.insert(choices, "#ysch3_moveBoard:"..from.id) end
    if #choices == 0 then return end
    if cancelable then table.insert(choices, "Cancel") end
    local choice = room:askForChoice(proposer, choices, skillName)
    if choice == "Cancel" then return end
    if choice:startsWith("#ysch3_moveHand") then targets = room:getOtherPlayers(from, false) end
    local t = room:askForChoosePlayers(proposer, table.map(targets, Util.IdMapper), 1, 1, "#ysch3-moveCard:"..from.id, skillName, cancelable)
    if #t > 0 then
        if choice:startsWith("#ysch3_moveHand") then
            local cid = room:askForCardChosen(proposer, from, "h", skillName)
            room:obtainCard(t[1], cid, false, fk.ReasonJustMove, proposer.id, skillName)
            return {cid,t[1]}
        else
            return {room:askForMoveCardInBoard(proposer, from, room:getPlayerById(t[1]), skillName, nil, from, {}).card.id,t[1]}
        end
    end
end
local yiji = fk.CreateActiveSkill{
    name = "ysch3_yiji",
    card_num = 0,
    target_num = 0,
    card_filter = Util.FalseFunc,
    target_filter = Util.FalseFunc,
    can_use = function (self, player, card, extra_data)
        return player:usedSkillTimes(self.name,Player.HistoryPhase) == 0
    end,
    prompt = "#ysch3_yiji",
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        player:drawCards(2,self.name)
        local num = 2
        local choice = room:askForChoice(player,{"#ysch3_yiji_add","Cancel"},self.name,"#ysch3_yiji-choice")
        if choice == "#ysch3_yiji_add" then
            num = 3
        end
        for i = 1, num, 1 do
            local cards = {}
            if num == 3 then
                for _, area in ipairs({Player.Hand,Player.Equip,Player.Judge}) do
                    if #player:getCardIds(area) == 1 then
                        table.insertIfNeed(cards,player:getCardIds(area)[1])
                    end
                end
            end
            local result = askForMoveCardFromPlayerArea(player,player,self.name,false)
            if num == 3 and result then
                local id, tp = result[1], result[2]
                if id and table.contains(cards,id) then
                    if room:askForSkillInvoke(player,self.name,nil,"#ysch3_yiji-invoked::"..tp) then
                        local tos = room:askForChoosePlayers(room:getPlayerById(tp), table.map(room.alive_players, Util.IdMapper), 1, 1, "#ysch3_yiji-damage", self.name, false)
                        if #tos > 0 then
                            room:damage { from = room:getPlayerById(tp), to = room:getPlayerById(tos[1]), damage = 1, skillName = self.name }
                        end
                    end
                end
            end
        end
    end,
}
wangbi:addSkill(yiji)
Fk:loadTranslationTable{
    ["ysch3_yiji"] = "移棘",
    [":ysch3_yiji"] = "出牌阶段限一次，你可以摸两张牌，再依次移动区域内两张牌。你可多移动一张牌，若如此做，一个区域因此技能清空时，你可令置入牌的角色分配1点伤害。",
    ["#ysch3_yiji"] = "移棘：你可以摸两张牌，再移动区域内两张牌。",
    ["#ysch3_yiji-choice"] = "移棘：你可以多移动一张牌",
    ["#ysch3_yiji_add"] = "多移动区域内一张牌",
    ["#ysch3_yiji-invoked"] = "移棘：是否令 %dest 分配1点伤害",
    ["#ysch3_yiji-damage"] = "移棘：分配1点伤害",
    ["#ysch3_moveHand"] = "移动 %src 的手牌",
    ["#ysch3_moveBoard"] = "移动 %src 场上牌",
    ["#ysch3-moveCard"] = "选择获得 %src 的牌的角色",
}
local zhaozi = General:new(extension, "ysch3__zhaozi", "wu", 3, 3, General.Male)--
--zhaozi.total_hidden = true
Fk:loadTranslationTable{
    ["ysch3__zhaozi"] = "赵咨",
    ["#ysch3__zhaozi"] = "吴魏契约",
    ["designer:ysch3__zhaozi"] = "铝",
    ["cv:ysch3__zhaozi"] = "无",
    ["illustrator:ysch3__zhaozi"] = "未知",
}
local sheyi = fk.CreateActiveSkill{
    name = "ysch3_sheyi",
    anim_type = "control",
    card_num = 0,
    target_num = 1,
    can_use = function(self, player)
        return not player:isKongcheng() and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected, selected_cards)
        return #selected == 0 and to_select ~= Self.id and Self:canPindian(Fk:currentRoom():getPlayerById(to_select))
    end,
    on_use = function(self, room, effect)
            local player = room:getPlayerById(effect.from)
            local target = room:getPlayerById(effect.tos[1])
            
            local req = Request:new({player, target}, "AskForChoice")
            req.focus_text = self.name
            req.receive_decode = false
            local choices1 = {"ysch3_sheyi11","ysch3_sheyi12"}
            req:setData(player, {choices1, choices1, self.name, "#ysch3_sheyi-choice::"..target.id})
            req:setDefaultReply(player, table.random(choices1))
            local choices2 = {"ysch3_sheyi11","ysch3_sheyi12"}
            req:setData(target, {choices2, choices2, self.name, "#ysch3_sheyi-choice::"..player.id})
            req:setDefaultReply(target, table.random(choices2))
            req:ask()
            
            for _, p in ipairs({player, target}) do
                room:sendLog{
                    type = "#Choice",
                    from = p.id,
                    arg = req:getResult(p)[13],
                    toast = true,
                }
            end
            local swapPindian = false
            if tonumber(req:getResult(player)[13]) == 1 then
                U.swapCards(room, player, player, target, player:getCardIds("h"), target:getCardIds("h"), self.name,Card.PlayerHand)
            else
                swapPindian = true
            end
            if tonumber(req:getResult(target)[13]) == 1 then
                U.swapCards(room, target, target, player, target:getCardIds("h"), player:getCardIds("h"), self.name,Card.PlayerHand)
            else
                swapPindian = not swapPindian
            end
            local pindian = {
                from = player,
                tos = {target},
                reason = self.name,
                fromCard = nil,
                results = {},
                extra_data = {
                    ysch3_sheyi = {
                        swapPindian = swapPindian,
                    }
                },
            }
            room:pindian(pindian)
            local sheyiWin = false
            if pindian.results[target.id].winner == player then
                sheyiWin = true
            elseif pindian.results[target.id].toCard.color == pindian.results[target.id].fromCard.color then
                sheyiWin = true
            end
            if sheyiWin == true then
                local req2 = Request:new({player, target}, "AskForChoice")
                req2.focus_text = self.name
                req2.receive_decode = false
                local choices3 = {"ysch3_sheyi21","ysch3_sheyi22"}
                req2:setData(player, {choices3, choices3, self.name, "#ysch3_sheyi-choice::"..target.id})
                req2:setDefaultReply(player, table.random(choices3))
                local choices4 = {"ysch3_sheyi31","ysch3_sheyi22"}
                req2:setData(target, {choices4, choices4, self.name, "#ysch3_sheyi-choice::"..player.id})
                req2:setDefaultReply(target, table.random(choices4))
                req2:ask()

                for _, p in ipairs({player, target}) do
                    room:sendLog{
                        type = "#Choice",
                        from = p.id,
                        arg = req2:getResult(p)[13],
                        toast = true,
                    }
                end
                if tonumber(req2:getResult(player)[13]) == 1 then
                    player:drawCards(1,self.name)
                else
                    player:setSkillUseHistory(self.name, 0, Player.HistoryPhase)
                end
                if tonumber(req2:getResult(target)[13]) == 1 then
                    player:drawCards(1,self.name)
                else
                    player:setSkillUseHistory(self.name, 0, Player.HistoryPhase)
                end
            end
    end,
}
local sheyi_trigger = fk.CreateTriggerSkill{
    name = "#ysch3_sheyi_trigger",
    refresh_events = {fk.PindianCardsDisplayed},
    can_refresh = function(self, event, target, player, data)
        return player:hasSkill("ysch3_sheyi") and player == data.from and data.reason == "ysch3_sheyi" and data.extra_data and data.extra_data.ysch3_sheyi and
        data.extra_data.ysch3_sheyi.swapPindian == true
    end,
    on_cost = Util.TrueFunc,
    mute = true,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        data.fromCard, data.results[data.tos[1].id].toCard = data.results[data.tos[1].id].toCard, data.fromCard
        data._fromCard, data.results[data.tos[1].id]._toCard = data.results[data.tos[1].id]._toCard, data._fromCard
        room:sendLog{
            type = "#ShowPindianCard",
            from = data.from.id,
            arg = data._fromCard:toLogString(),
        }
        room:sendLog{
            type = "#ShowPindianCard",
            from = data.tos[1].id,
            arg = data.results[data.tos[1].id]._toCard:toLogString(),
        }
    end,
}
sheyi:addRelatedSkill(sheyi_trigger)
zhaozi:addSkill(sheyi)
local shipin = fk.CreateViewAsSkill{
    name = "ysch3_shipin",
    anim_type = "defensive",
    prompt = "#ysch3_shipin",
    pattern = "slash,jink",
    interaction = function()
        local names = {}
        for _, name in ipairs({"slash","jink"}) do
        local card = Fk:cloneCard(name)
        if (Fk.currentResponsePattern == nil and Self:canUse(card)) or
            (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card)) then
            table.insertIfNeed(names, card.name)
        end
        end
        if #names == 0 then return end
        return U.CardNameBox {choices = names}
    end,
    card_filter = Util.FalseFunc,
    view_as = function(self)
        if not self.interaction.data then return end
        local card = Fk:cloneCard(self.interaction.data)
        card.skillName = self.name
        return card
    end,
    before_use = function(self, player, use)
        local room = player.room
        if use.tos then
            room:doIndicate(player.id, TargetGroup:getRealTargets(use.tos))
        end

        local askTargets = {}
        for _, sp in ipairs(room:getOtherPlayers(player)) do
            if table.every(room:getOtherPlayers(player), function (cp)
                return sp:distanceTo(player) >= cp:distanceTo(player)
            end) or table.every(room:getOtherPlayers(player), function (cp)
                return sp:distanceTo(player) <= cp:distanceTo(player)
            end) then
                table.insert(askTargets,sp)
            end
        end
        for _, target in ipairs(askTargets) do
            local cardResponded = room:askForResponse(target, use.card.name, use.card.name, "#ysch3_shipin-ask:"..player.id.."::"..use.card.name, true)
            if cardResponded then
                room:responseCard({
                    from = target.id,
                    card = cardResponded,
                    skipDrop = true,
                })
                use.card = cardResponded
                return
            end
        end
        return self.name
    end,
    enabled_at_play = function(self, player)
        return player.phase == Player.NotActive
    end,
    enabled_at_response = function(self, player, response)
        return not response and player.phase == Player.NotActive
    end,
}
zhaozi:addSkill(shipin)
Fk:loadTranslationTable{
    ["ysch3_sheyi"] = "舌仪",
    [":ysch3_sheyi"] = "出牌阶段限一次，你可以与一名其他角色拼点，结算前，双方同时选择：1.交换拼点牌；2.交换手牌。若你拼点牌的同色牌赢，双方再同时选择：1.你摸一张牌；2.重置此技能。",
    ["#ysch3_sheyi-choice"] = "舌仪：与 %dest 同时选择一项执行",
    ["ysch3_sheyi11"] = "交换手牌",
    ["ysch3_sheyi12"] = "交换拼点牌",
    ["ysch3_sheyi21"] = "你摸一张牌",
    ["ysch3_sheyi22"] = "重置此技能",
    ["ysch3_sheyi31"] = "其摸一张牌",
    ["ysch3_shipin"] = "使聘",
    [":ysch3_shipin"] = "你的回合外，距离你最近或最远的其他角色可替你使用【杀】或【闪】。",
    ["#ysch3_shipin"] = "使聘：是否令距离你最近或最远的其他角色替你使用【杀】或【闪】？",
    ["#ysch3_shipin-ask"] = "使聘：是否替 %src 使用【%arg】？",
    ["@ysch3_shipin"] = "最近或最远",
}
local chenshou = General:new(extension, "ysch3__chenshou", "jin", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch3__chenshou"] = "陈寿",
    ["#ysch3__chenshou"] = "寿笔难删",
    ["designer:ysch3__chenshou"] = "铝",
    ["cv:ysch3__chenshou"] = "无",
    ["illustrator:ysch3__chenshou"] = "未知",
}
Fk:addQmlMark{
    name = "ysch3_yinwen",
    how_to_show = function(name, value)
        if type(value) == "string" then
            return Fk:translate(value)
        elseif type(value) == "table" then
            return tostring(#value)
        end
        return " "
    end,
    qml_path = "packages/ysch_Al/qml/YinwenDetailBox"
}
local kuidian = fk.CreateActiveSkill{
    name = "ysch3_kuidian",
    interaction = function (self, player)
        return UI.ComboBox {choices = player:getTableMark("@[ysch3_yinwen]")}
    end,
    can_use = function (self, player, card, extra_data)
        local mark = player:getTableMark("@[ysch3_yinwen]")
        return #mark > 0
    end,
    card_num = 0,
    card_filter = Util.FalseFunc,
    target_num = 1,
    target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
        if to_select == player.id and player:getMark("ysch3_kuidian") >= 3 then
            return false
        end
        return #selected == 0
    end,
    times = function(self)
        return Self.phase == Player.Play and 3 - Self:getMark("ysch3_kuidian") or -1
    end,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        local target = room:getPlayerById(effect.tos[1])
        if player.id == target.id then
            room:addPlayerMark(player,"ysch3_kuidian",1)
        end
        local skill = self.interaction.data
        local mark = player:getTableMark("@[ysch3_yinwen]")
        table.removeOne(mark,skill)
        room:setPlayerMark(player,"@[ysch3_yinwen]",mark)
        room:handleAddLoseSkills(target,skill)
    end,
}
chenshou:addSkill(kuidian)
local cailu = fk.CreateTriggerSkill{
    name = "ysch3_cailu",
    dynamic_desc = function (self, player, lang)
        local str = "一名角色的回合结束时，你可选择一名本回合发动过不在其武将牌上技能的其他角色，令其交给你一张不在游戏牌堆内的牌。若做不到，将其的一个技能加入你的“引文”。"
        local mark = player:getTableMark("@[ysch3_yinwen]")
        if #mark > 0 then
            for _, value in ipairs(mark) do
                str = str .. "<br><br><i><font color = '#a40000'>“"..Fk:translate(":"..value).."”——"..Fk:translate(value).."</font></i>"
            end
        end
        return str
    end,
    events = {fk.TurnEnd},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) then
            for _, sp in ipairs(player.room:getOtherPlayers(player, false)) do
                for _, s in ipairs(sp:getAllSkills()) do
                    if sp:usedSkillTimes(s.name, Player.HistoryTurn) ~= 0 and not table.contains(Fk.generals[sp.general]:getSkillNameList(true),s.name) and
                    (sp.deputyGeneral == "" or not table.contains(Fk.generals[sp.deputyGeneral]:getSkillNameList(true),s.name)) then
                        return true
                    end
                end
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local targets = {}
        for _, sp in ipairs(player.room:getOtherPlayers(player, false)) do
            for _, s in ipairs(sp:getAllSkills()) do
                if sp:usedSkillTimes(s.name, Player.HistoryTurn) ~= 0 and not table.contains(Fk.generals[sp.general]:getSkillNameList(true),s.name) and
                (sp.deputyGeneral == "" or not table.contains(Fk.generals[sp.deputyGeneral]:getSkillNameList(true),s.name)) then
                    table.insertIfNeed(targets,sp.id)
                end
            end
        end
        local to = room:askForChoosePlayers(player, targets, 1, 1, "#ysch3_cailu-choose", self.name, true)
        if #to > 0 then
            self.cost_data = {tos = to}
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local target = room:getPlayerById(self.cost_data.tos[1])
        local cards = table.filter(player:getCardIds("he"), function (id)
            local name = Fk:getCardById(id).name
            return not table.contains(getAllCardNames("btde"),name)
        end)
        local card = room:askForCard(target, 1, 1, true, self.name, true, tostring(Exppattern{ id = cards }), "#ysch3_cailu-give::"..player.id)
        if #card > 0 then
            room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonGive, self.name, nil, false, target.id)
        else
            local player_skills = {}
            for _, skill in ipairs(target.player_skills) do
                if skill:isPlayerSkill(target) and not skill.name:startsWith("#") and not skill.attached_equip then
                    table.insert(player_skills, skill.name)
                end
            end
            local choice = room:askForChoice(player, player_skills, self.name, "#ysch3_cailu-skill::"..target.id, true)
            room:handleAddLoseSkills(target, "-"..choice, nil, true, false)
            local mark = player:getTableMark("@[ysch3_yinwen]")
            table.insert(mark,choice)
            room:setPlayerMark(player,"@[ysch3_yinwen]",mark)
        end
    end,

    on_acquire = function (self, player, is_start)
        if type(player:getMark("@[ysch3_yinwen]")) ~= "table" then
            player.room:setPlayerMark(player,"@[ysch3_yinwen]",{"yschAl_yingzi"})
        end
    end,
}
chenshou:addSkill(cailu)
local yingzi = fk.CreateTriggerSkill{
    name = "yschAl_yingzi",
    anim_type = "drawcard",
    events = {fk.DrawNCards},
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        data.n = data.n + 1
    end,
}
yingzi.permanent_skill = true
Fk:addSkill(yingzi)
Fk:loadTranslationTable{
    ["ysch3_kuidian"] = "揆典",
    [":ysch3_kuidian"] = "出牌阶段，你可将你的一条“引文”移给一名角色作为技能。（对你限三次）",
    ["ysch3_cailu"] = "采录",
    [":ysch3_cailu"] = "一名角色的回合结束时，你可选择一名本回合发动过不在其武将牌上技能的其他角色，令其交给你一张不在游戏牌堆内的牌。若做不到，将其的一个技能加入你的“引文”。<br><br><i><font color = '#a40000'>“持恒技，摸牌阶段，你多摸一张牌。”——英姿</font></i>",
    ["#ysch3_cailu-choose"] = "是否发动 采录，采录一名其他角色的技能？",
    ["#ysch3_cailu-give"] = "采录：交给 %dest 一张不在游戏牌堆内的牌，否则其采录你的一个技能",
    ["#ysch3_cailu-skill"] = "请你采录 %dest 的一个技能",
    ["@[ysch3_yinwen]"] = "引文",
    ["yschAl_yingzi"] = "英姿",
    [":yschAl_yingzi"] = "持恒技，摸牌阶段，你多摸一张牌。",
}
return extension